A box is created with its deprecated constructor
What it finds
new Integer(42) and the other constructors of the boxes are deprecated for removal: they make a new object every time, where Integer.valueOf(42) can return a shared one.
The fix calls valueOf instead. Code that compares the results by reference, or locks on them, could notice the shared objects, so the fix is offered as unsafe.
From the rule's source, boxing_constructor.rs.
class Boxes { Object[] make(int i, String s) { return new Object[] { new Integer(i),tx0 reports: new Integer is deprecated for removal new Long(5L),tx0 reports: new Long is deprecated for removal new java.lang.Double(s),tx0 reports: new Double is deprecated for removal Integer.valueOf(i), new StringBuilder(s), }; }} 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:boxing-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:boxing-constructor] reason="..."tx0 explain tx0/java:boxing-constructor shows the same in the terminal. Found a false positive? Report it.