Skip to content

java: ? and : count as branches inside string literals, and a ternary counts twice #4170

Closed

Description

@squid-protocol

Problem

In Java, branch and complexity counting (struct_branch, per-function complexity) counts every ? and every : as a decision point:

  • Inside string literals. JDBC ? placeholders and SQL :host variables each add a branch.
  • Real ternaries. a ? b : c adds 2 instead of 1.

Minimal repro (main at 582caf5), each method has one if:

Method body besides the if complexity
String s = "hello"; 1
String s = "(?, ?, ?, ?, ?)"; 6
String s = "(:a, :b, :c, :d, :e)"; 6
String s = "where a = ?"; 2
String s = x > 1 ? "a" : "b"; 3 (should be 2)

Impact

#2833 dealt with Java's bare :. This is a regression, or what it left out.

Fix

In progress on branch fix/java-ternary-string-branches:

Activity

  1. added
    scope:frontier
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope:frontier

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions