Skip to content

Declare never-null local variables as primitives (CodeQL java/non-null-boxed-variable)#237

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

Declare never-null local variables as primitives (CodeQL java/non-null-boxed-variable)#237
vharseko wants to merge 2 commits into
OpenIdentityPlatform:masterfrom
vharseko:features/codeql-non-null-boxed

Conversation

@vharseko

@vharseko vharseko commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

Resolves all seven open java/non-null-boxed-variable CodeQL alerts. Each local
variable was declared with a boxed wrapper type but only ever assigned a
primitive value and never null, so it paid for boxing plus an implicit unbox on
every use. Each is now declared with the matching primitive type.

File Line(s) Variable Was → Now
DateUtil.java 207, 208 l, r Longlong
MemoryBackend.java 363 n1, n2 Doubledouble
JsonValueUtils.java 482 n1, n2 Doubledouble
ThreadSequencer.java 205 location Integerint
InstallExternalDependencyMojo.java 84, 104 cachedCreateChecksums, artifactAlreadyInstalled Booleanboolean

Why this is behaviour-preserving

  • DateUtill/r are computed from long arithmetic; r.intValue()
    becomes (int) r (identical narrowing). The nullable result stays Integer.
  • MemoryBackend / JsonValueUtilsn1.compareTo(n2) on Double is
    replaced by Double.compare(n1, n2), which is exactly the primitive comparison
    Double.compareTo delegates to (same NaN / -0.0 ordering).
  • ThreadSequencer — the loop iterates an int[]; appendHistoryElement
    already accepts an int, so nothing downstream changes.
  • InstallExternalDependencyMojocachedCreateChecksums comes from the
    boolean createChecksum field and is written back to it; artifactAlreadyInstalled
    comes from File.exists() and is only used in a boolean expression.

Every value was already unboxed at its point of use, so there is no behavioural
change.

Testing

mvn -o -pl persistit/core,commons/audit/core,commons/rest/json-resource,maven-external-dependency-plugin/maven-external-dependency-plugin compile — each module builds (BUILD SUCCESS).

…l-boxed-variable)

Seven local variables were declared with a boxed type (Integer/Long/Double/
Boolean) but only ever hold a primitive value and are never null, so each
incurred needless boxing and an implicit unbox on every use. Declare them with
the corresponding primitive type:

  - DateUtil.getDateDifferenceInDays: l and r become long; r.intValue() becomes
    the equivalent (int) r cast. The nullable result stays Integer.
  - MemoryBackend.compareValues and JsonValueUtils.compareValues: n1/n2 become
    double and the comparison uses Double.compare(n1, n2), which is exactly what
    Double.compareTo already delegated to (same NaN / -0.0 ordering).
  - ThreadSequencer.describeHistory: iterate the int[] with a primitive int;
    appendHistoryElement already takes an int.
  - InstallExternalDependencyMojo: cachedCreateChecksums (from a boolean field)
    and artifactAlreadyInstalled (from File.exists()) become boolean.

Each value was already unboxed at its point of use, so behaviour is unchanged.
@vharseko vharseko requested a review from maximthomas July 8, 2026 13:56
@vharseko vharseko added codeql CodeQL static-analysis findings refactoring Code cleanup / refactoring, no behavior change labels Jul 8, 2026
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