Skip to content

Replace deprecated primitive-wrapper constructors with valueOf (java:S2129) - #9

Open
trly wants to merge 1 commit into
mainfrom
sonar-s2129-wrapper-valueof-ecec716d-6a6f-4d14-bf20-9229d498a918
Open

Replace deprecated primitive-wrapper constructors with valueOf (java:S2129)#9
trly wants to merge 1 commit into
mainfrom
sonar-s2129-wrapper-valueof-ecec716d-6a6f-4d14-bf20-9229d498a918

Conversation

@trly

@trly trly commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Fixes SonarQube rule java:S2129 ("Constructors should not be used to instantiate primitive-wrapper classes") in this repository.

Every new Boolean(...), new Byte(...), new Character(...), new Double(...), new Float(...), new Integer(...), new Long(...) and new Short(...) call is replaced with the corresponding valueOf(...) factory method. These constructors are deprecated for removal since Java 9; valueOf is the documented replacement and allows the JVM to reuse cached instances instead of allocating a new object for every value.

The change is behaviour-preserving: the resulting values compare equal via equals() and unbox to identical primitives.

Created by Sourcegraph agentic batch change.

Addresses SonarQube java:S2129 by switching new Boolean/Byte/Character/
Double/Float/Integer/Long/Short(...) calls to the corresponding
valueOf(...) factory methods.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant