Two strings are compared after changing their case, where equalsIgnoreCase does it directly
What it finds
a.toLowerCase().equals(b.toLowerCase()) creates two new strings to compare them, and depends on the default locale; a.equalsIgnoreCase(b) compares without copies and without the locale.
Reported is equals between two calls of toLowerCase() or two of toUpperCase() without arguments.
From the rule's source, case_folded_comparison.rs.
class Names { boolean same(String a, String b) { boolean x = a.toLowerCase().equals(b.toLowerCase());tx0 reports: equalsIgnoreCase compares directly boolean y = a.equalsIgnoreCase(b); return x || y; }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/java:case-folded-comparison" = "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:case-folded-comparison] reason="..."tx0 explain tx0/java:case-folded-comparison shows the same in the terminal. Found a false positive? Report it.