From 7dd40dfb432389583c56246669d0638989b1a155 Mon Sep 17 00:00:00 2001 From: Valera V Harseko Date: Wed, 8 Jul 2026 18:45:09 +0300 Subject: [PATCH] Replace boxed-primitive constructors with valueOf (CodeQL java/inefficient-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. --- .../session/jwt/AbstractJwtSessionModule.java | 2 +- .../java/com/persistit/DefaultValueCoder.java | 2 +- .../main/java/com/persistit/ManagementImpl.java | 13 +++++++------ .../src/main/java/com/persistit/Persistit.java | 2 +- persistit/examples/FindFile/FindFile.java | 3 ++- .../com/persistit/ui/ValueInspectorTreeNode.java | 15 ++++++++------- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/commons/auth-filters/authn-filter/jaspi-modules/jwt-session-module/src/main/java/org/forgerock/jaspi/modules/session/jwt/AbstractJwtSessionModule.java b/commons/auth-filters/authn-filter/jaspi-modules/jwt-session-module/src/main/java/org/forgerock/jaspi/modules/session/jwt/AbstractJwtSessionModule.java index 722a8b2a3f..f3a1901659 100644 --- a/commons/auth-filters/authn-filter/jaspi-modules/jwt-session-module/src/main/java/org/forgerock/jaspi/modules/session/jwt/AbstractJwtSessionModule.java +++ b/commons/auth-filters/authn-filter/jaspi-modules/jwt-session-module/src/main/java/org/forgerock/jaspi/modules/session/jwt/AbstractJwtSessionModule.java @@ -563,7 +563,7 @@ private String buildJwtString(JwtClaimsSet claimsSet, Key publicKey) { */ private int getCookieMaxAge(Date now, Date exp) { if (!browserSessionOnly) { - return new Long((exp.getTime() - now.getTime()) / 1000L).intValue(); + return Long.valueOf((exp.getTime() - now.getTime()) / 1000L).intValue(); } else { return -1; } diff --git a/persistit/core/src/main/java/com/persistit/DefaultValueCoder.java b/persistit/core/src/main/java/com/persistit/DefaultValueCoder.java index 2c5393fe8d..86e0d92dd3 100644 --- a/persistit/core/src/main/java/com/persistit/DefaultValueCoder.java +++ b/persistit/core/src/main/java/com/persistit/DefaultValueCoder.java @@ -379,7 +379,7 @@ private static Accessor lookupAccessor(final Class clazz, final String name) { final char ch = name.charAt(0); if (Character.isLetter(ch) && Character.isLowerCase(ch)) { - baseName = new Character(Character.toUpperCase(ch)) + name.substring(1); + baseName = Character.valueOf(Character.toUpperCase(ch)) + name.substring(1); } else { baseName = name; } diff --git a/persistit/core/src/main/java/com/persistit/ManagementImpl.java b/persistit/core/src/main/java/com/persistit/ManagementImpl.java index b1ed8ffa17..d4cc265602 100644 --- a/persistit/core/src/main/java/com/persistit/ManagementImpl.java +++ b/persistit/core/src/main/java/com/persistit/ManagementImpl.java @@ -12,6 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * Portions Copyrighted 2026 3A Systems, LLC */ package com.persistit; @@ -345,7 +346,7 @@ public BufferPoolInfo[] getBufferPoolInfoArray() { final BufferPoolInfo[] result = new BufferPoolInfo[size]; int index = 0; for (int bufferSize = Buffer.MIN_BUFFER_SIZE; bufferSize <= Buffer.MAX_BUFFER_SIZE; bufferSize *= 2) { - final BufferPool pool = bufferPoolTable.get(new Integer(bufferSize)); + final BufferPool pool = bufferPoolTable.get(Integer.valueOf(bufferSize)); if (pool != null && index < size) { final BufferPoolInfo info = new BufferPoolInfo(); @@ -1050,7 +1051,7 @@ public synchronized long startTask(final String description, final String owner, final long taskId = ++_taskIdCounter; task.setPersistit(_persistit); task.setup(taskId, description, owner, maximumTime, verbosity); - _tasks.put(new Long(taskId), task); + _tasks.put(Long.valueOf(taskId), task); task.start(); return taskId; } catch (final Exception ex) { @@ -1153,7 +1154,7 @@ public synchronized void setTaskSuspended(final long taskId, final boolean suspe task.resume(); } } else { - final Task task = _tasks.get(new Long(taskId)); + final Task task = _tasks.get(Long.valueOf(taskId)); if (task != null) { if (suspend) task.suspend(); @@ -1185,11 +1186,11 @@ public synchronized void stopTask(final long taskId, final boolean remove) { _tasks.clear(); } } else { - final Task task = _tasks.get(new Long(taskId)); + final Task task = _tasks.get(Long.valueOf(taskId)); if (task != null) { task.stop(); if (remove) { - _tasks.remove(new Long(task._taskId)); + _tasks.remove(Long.valueOf(task._taskId)); } } } @@ -1310,7 +1311,7 @@ public synchronized String launch(final Task task, final String description) thr try { final long taskId = taskId(); task.setup(taskId, description, Thread.currentThread().getName(), 0, 5); - _tasks.put(new Long(taskId), task); + _tasks.put(Long.valueOf(taskId), task); task.start(); return Long.toString(taskId); } catch (final Exception ex) { diff --git a/persistit/core/src/main/java/com/persistit/Persistit.java b/persistit/core/src/main/java/com/persistit/Persistit.java index 7bf86b3884..ad957ac622 100644 --- a/persistit/core/src/main/java/com/persistit/Persistit.java +++ b/persistit/core/src/main/java/com/persistit/Persistit.java @@ -1497,7 +1497,7 @@ private Volume getSpecialVolume(final String propName, final String dflt) throws * @return the BufferPool for the specific buffer size */ BufferPool getBufferPool(final int size) { - return _bufferPoolTable.get(new Integer(size)); + return _bufferPoolTable.get(Integer.valueOf(size)); } /** diff --git a/persistit/examples/FindFile/FindFile.java b/persistit/examples/FindFile/FindFile.java index b288264cb5..dca41d6f48 100644 --- a/persistit/examples/FindFile/FindFile.java +++ b/persistit/examples/FindFile/FindFile.java @@ -12,6 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * Portions Copyrighted 2026 3A Systems, LLC */ import java.awt.BorderLayout; @@ -293,7 +294,7 @@ private void traverseFileNames(String fixed, Pattern pattern, boolean forward) { KeyFilter filter = new KeyFilter(ex.getKey()); if (fixed.length() != 0) { String end = fixed.substring(0, fixed.length() - 1) - + new Character((char) (fixed.charAt(fixed.length() - 1) + 1)); + + Character.valueOf((char) (fixed.charAt(fixed.length() - 1) + 1)); // // append a Term that selects only the range accepted by the // fixed portion of the name. diff --git a/persistit/ui/src/main/java/com/persistit/ui/ValueInspectorTreeNode.java b/persistit/ui/src/main/java/com/persistit/ui/ValueInspectorTreeNode.java index 3eb835090b..d5d01a3152 100644 --- a/persistit/ui/src/main/java/com/persistit/ui/ValueInspectorTreeNode.java +++ b/persistit/ui/src/main/java/com/persistit/ui/ValueInspectorTreeNode.java @@ -12,6 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * Portions Copyrighted 2026 3A Systems, LLC */ package com.persistit.ui; @@ -378,19 +379,19 @@ private ValueInspectorTreeNode getArrayChild(final int index) { if (elementType == boolean.class) { element = ((boolean[]) _object)[index] ? Boolean.TRUE : Boolean.FALSE; } else if (elementType == byte.class) { - element = new Byte(((byte[]) _object)[index]); + element = Byte.valueOf(((byte[]) _object)[index]); } else if (elementType == short.class) { - element = new Short(((short[]) _object)[index]); + element = Short.valueOf(((short[]) _object)[index]); } else if (elementType == char.class) { - element = new Character(((char[]) _object)[index]); + element = Character.valueOf(((char[]) _object)[index]); } else if (elementType == int.class) { - element = new Integer(((int[]) _object)[index]); + element = Integer.valueOf(((int[]) _object)[index]); } else if (elementType == long.class) { - element = new Long(((long[]) _object)[index]); + element = Long.valueOf(((long[]) _object)[index]); } else if (elementType == float.class) { - element = new Float(((float[]) _object)[index]); + element = Float.valueOf(((float[]) _object)[index]); } else if (elementType == double.class) { - element = new Double(((double[]) _object)[index]); + element = Double.valueOf(((double[]) _object)[index]); } else throw new RuntimeException(); } else {