A string is copied with new String, which only makes a duplicate
What it finds
Strings are immutable, so new String("text") or new String(name) only makes a second object with the same characters, which takes memory and defeats == on interned literals. The original string serves the same purpose.
Reported is new String(x) with a single argument of type String.
From the rule's source, string_copy_constructor.rs.
class Copies { String copy(String name, char[] chars) { String a = new String(name);tx0 reports: copies a string String b = new String(chars); return a + b; }} 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:string-copy-constructor" = "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:string-copy-constructor] reason="..."tx0 explain tx0/java:string-copy-constructor shows the same in the terminal. Found a false positive? Report it.