Skip to content

Replace boxed-primitive constructors with valueOf (CodeQL java/inefficient-boxed-constructor)#247

Open
vharseko wants to merge 2 commits into
OpenIdentityPlatform:masterfrom
vharseko:features/codeql-boxed-constructor
Open

Replace boxed-primitive constructors with valueOf (CodeQL java/inefficient-boxed-constructor)#247
vharseko wants to merge 2 commits into
OpenIdentityPlatform:masterfrom
vharseko:features/codeql-boxed-constructor

Conversation

@vharseko

@vharseko vharseko commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

Resolves the CodeQL java/inefficient-boxed-constructor alerts (17 open) by replacing deprecated boxed-primitive constructors with the corresponding valueOf(...) factory methods.

new Integer(x) / new Long(x) / … always allocate a fresh object and have been deprecated since Java 9. X.valueOf(x) is the recommended form: it avoids the redundant allocation and may reuse cached instances. The change is behavior-preserving — equal values with identical equals/hashCode; none of the touched sites rely on reference identity (==).

Changes (17 replacements across 6 files)

File Module Replacements
AbstractJwtSessionModule.java commons/auth-filters (jwt-session-module) Long
DefaultValueCoder.java persistit/core Character
ManagementImpl.java persistit/core Integer, 5× Long
Persistit.java persistit/core Integer
FindFile.java persistit/examples Character
ValueInspectorTreeNode.java persistit/ui Byte, Short, Character, Integer, Long, Float, Double

Verification

  • Compiled persistit/core, persistit/ui and the jaspi jwt-session-module (all clean).
  • javac for the FindFile persistit Ant example (not part of the Maven reactor).

Annotation of the fix is purely local (new X(X.valueOf(); arguments and surrounding expressions are unchanged.

@vharseko vharseko requested a review from maximthomas July 8, 2026 15:45
@vharseko vharseko added codeql CodeQL static-analysis findings refactoring Code cleanup / refactoring, no behavior change labels Jul 8, 2026
…cient-boxed-constructor)

Replace 17 uses of the deprecated boxed-primitive constructors
(new Long/Integer/Short/Byte/Character/Float/Double(...)) with the
corresponding X.valueOf(...) factory methods across 6 files. valueOf
avoids an unnecessary allocation and may reuse cached instances; the
change is behavior-preserving (equal values, same equals/hashCode).
Verified by compiling persistit/core, persistit/ui and the jaspi
jwt-session-module, plus javac for the persistit FindFile Ant example.
@vharseko vharseko force-pushed the features/codeql-boxed-constructor branch from 267cbf5 to 7dd40df Compare July 8, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codeql CodeQL static-analysis findings refactoring Code cleanup / refactoring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants