A box is created only to convert or print its value, where a static method does it directly
What it finds
Integer.valueOf(text).intValue() boxes the parsed number only to unbox it again, and new Integer(count).toString() creates an object only to print it. Integer.parseInt and Integer.toString(count) do the same without the box.
Reported is intValue() and its kin, or toString(), called directly on Integer.valueOf(...), new Integer(...) and the same for the other numeric boxes and Boolean.
From the rule's source, needless_boxing.rs.
class Convert { String run(String text, int count) { int a = Integer.valueOf(text).intValue();tx0 reports: creates a box only to convert its value String b = Integer.valueOf(count).toString();tx0 reports: creates a box int c = Integer.parseInt(text); String d = Integer.toString(count); return a + b + c + d; }} 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:needless-boxing" = "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:needless-boxing] reason="..."tx0 explain tx0/java:needless-boxing shows the same in the terminal. Found a false positive? Report it.