A box is created with its deprecated constructor

tx0/java:boxing-constructorrecommendedwarningdeprecated, performance

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.

Example from the rule's tests
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),    };  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

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.