The result of indexOf is compared with > 0, which misses a match at the start

tx0/java:index-of-positivestrictwarningbug

What it finds

name.indexOf(':') > 0 is false when the colon is the first character: indexOf returns 0 for a match at the start and -1 for none, as the String documentation says. The test for a match is >= 0, or contains.

Reported is indexOf(...) > 0 or 0 < indexOf(...) on a string.

From the rule's source, index_of_positive.rs.

Example from the rule's tests
class Parse {  boolean check(String name) {    boolean a = name.indexOf(':') > 0;tx0 reports: misses a match at index 0    boolean b = name.indexOf(':') >= 0;    boolean c = 0 < name.indexOf("x");tx0 reports: misses a match    return a || b || c;  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:index-of-positive" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:index-of-positive] reason="..."

tx0 explain tx0/java:index-of-positive shows the same in the terminal. Found a false positive? Report it.