Declare never-null local variables as primitives (CodeQL java/non-null-boxed-variable)#237
Open
vharseko wants to merge 2 commits into
Open
Conversation
…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.
maximthomas
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves all seven open
java/non-null-boxed-variableCodeQL alerts. Each localvariable 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 onevery use. Each is now declared with the matching primitive type.
DateUtil.javal,rLong→longMemoryBackend.javan1,n2Double→doubleJsonValueUtils.javan1,n2Double→doubleThreadSequencer.javalocationInteger→intInstallExternalDependencyMojo.javacachedCreateChecksums,artifactAlreadyInstalledBoolean→booleanWhy this is behaviour-preserving
DateUtil—l/rare computed fromlongarithmetic;r.intValue()becomes
(int) r(identical narrowing). The nullableresultstaysInteger.MemoryBackend/JsonValueUtils—n1.compareTo(n2)onDoubleisreplaced by
Double.compare(n1, n2), which is exactly the primitive comparisonDouble.compareTodelegates to (sameNaN/-0.0ordering).ThreadSequencer— the loop iterates anint[];appendHistoryElementalready accepts an
int, so nothing downstream changes.InstallExternalDependencyMojo—cachedCreateChecksumscomes from theboolean createChecksumfield and is written back to it;artifactAlreadyInstalledcomes 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).