jlerbsc opened a new pull request, #1768:
URL: https://github.com/apache/commons-lang/pull/1768
## What
Replaces a few remaining occurrences of:
- `new String(s)` -> `s`
- `new Integer(i)` / `new Long(l)` / `new Boolean(b)` / `new Double(d)` ->
`Integer.valueOf(i)` / ...
<!-- TODO: paste the actual list here, e.g.
- `src/main/java/org/apache/commons/lang3/Xxx.java:123`
-->
## Why
These constructors always allocate a new object, while the `valueOf()`
factory methods return cached instances for the common value ranges, so
the change is a small allocation win on hot paths and a no-op elsewhere.
The primitive-wrapper constructors have also been deprecated since
Java 9 (`forRemoval` since Java 16), so removing them keeps the code
ready for newer JDKs.
This corresponds to Sonar rule S2129, "Constructors should not be used to
instantiate String, BigInteger, BigDecimal and the primitive wrapper
classes".
## Scope / non-goals
- Only `src/main/java` is touched. The occurrences in the test sources
are deliberate: they create distinct instances to assert reference
identity (`assertNotSame`, `equals` vs `==` contracts), so changing
them would weaken the tests. They are left as-is.
- No public API, behaviour or nullability change. The only observable
difference is object identity, and I checked that none of the touched
values are used as lock monitors or in identity-based collections
(`IdentityHashMap`, `==` comparisons).
- `mvn clean verify` passes locally. <!-- adapte si tu as lancé autre chose
-->
## How this was found
I ran the project through Indepth, a static analysis tool I develop, as
part of validating its rule set against real-world code bases. Full
disclosure: I am the author of Indepth, and I am also a committer on the
JavaParser project. Indepth is free to use for open source projects, so
if the Commons team is interested I am happy to share the full report for
commons-lang, or to help set it up on the project. Either way, this PR
stands on its own and there is no obligation attached to it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]