An array is turned into a string or hash code by identity
What it finds
"values: " + values with an array, or values.toString(), gives something like [I@1b6d3586, the array's type and identity hash code, not its elements; so does values.hashCode(), which differs between equal arrays. Arrays.toString and Arrays.hashCode look at the elements.
Only operands whose declared type is an array are reported. A char[] printed with println or passed to String.valueOf shows its characters, but not in a concatenation, which is reported too.
From the rule's source, array_to_string.rs.
class Dump { String show(int[] values, char[] chars, String[] names, Object o) { String a = "values: " + values;tx0 reports: values is an array String b = names.toString();tx0 reports: names is an array int c = values.hashCode();tx0 reports: values is an array String d = chars + "!";tx0 reports: chars is an array String e = java.util.Arrays.toString(values); String f = "o: " + o; String g = String.valueOf(chars); return a + b + c + d + e + f + g; }} 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:array-to-string" = "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:array-to-string] reason="..."tx0 explain tx0/java:array-to-string shows the same in the terminal. Found a false positive? Report it.