From b7778b8b3b65626e6c4602e72a96cec60fe59d23 Mon Sep 17 00:00:00 2001 From: Valera V Harseko Date: Wed, 8 Jul 2026 14:44:06 +0300 Subject: [PATCH] Widen int multiplications to long before conversion (CodeQL java/integer-multiplication-cast-to-long) In each case the product was computed in int arithmetic and only then widened to long, so a large enough operand overflows before the conversion. Add an L suffix to the first factor so the multiplication is performed in long. - JournalManagerBench.runTest: prealloc*1024*1024 (passed to preallocateFile(long)) and extension*1024*1024 (assigned to a long) convert an MByte argument to a byte count; use 1024L so the byte count is exact for any int MByte value. - SimpleTransaction: _committedTransactionCount * 1000 is evaluated as int before the division by the long "time"; the committed count can exceed ~2.1M in a long-running run, overflowing the rate calculation. Use 1000L. - AdminUI.resetRefreshTimer: _refreshInterval (int seconds) * 1000 is passed as the long period of Timer.schedule; use 1000L. Behaviour is unchanged for in-range inputs; only the silent int overflow at large inputs is removed. These are benchmark/example/admin-UI classes, not core data paths. --- .../src/main/java/com/persistit/JournalManagerBench.java | 5 +++-- persistit/examples/SimpleTransaction/SimpleTransaction.java | 3 ++- persistit/ui/src/main/java/com/persistit/ui/AdminUI.java | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/persistit/core/src/main/java/com/persistit/JournalManagerBench.java b/persistit/core/src/main/java/com/persistit/JournalManagerBench.java index 958e73353a..549e81b83a 100644 --- a/persistit/core/src/main/java/com/persistit/JournalManagerBench.java +++ b/persistit/core/src/main/java/com/persistit/JournalManagerBench.java @@ -1,5 +1,6 @@ /** * Copyright 2012 Akiban Technologies, Inc. + * Portions Copyrighted 2026 3A Systems, LLC. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -87,12 +88,12 @@ private JournalManagerBench(final String[] args) throws Exception { private void runTest() throws Exception { file = new File(ap.getStringValue("datapath"), "JManBench_TestFile"); fc = new RandomAccessFile(file, "rw").getChannel(); - preallocateFile(ap.getIntValue("prealloc") * 1024 * 1024); + preallocateFile(ap.getIntValue("prealloc") * 1024L * 1024); for (int i = 0; i < bytes.length; i++) { bytes[i] = (byte) ('-'); } final int align = ap.getIntValue("align"); - final long extension = ap.getIntValue("extension") * 1024 * 1024; + final long extension = ap.getIntValue("extension") * 1024L * 1024; final long start = System.nanoTime(); final long expires = start + ap.getIntValue("duration") * NS_PER_S; diff --git a/persistit/examples/SimpleTransaction/SimpleTransaction.java b/persistit/examples/SimpleTransaction/SimpleTransaction.java index becd7cd77f..b28758814a 100644 --- a/persistit/examples/SimpleTransaction/SimpleTransaction.java +++ b/persistit/examples/SimpleTransaction/SimpleTransaction.java @@ -1,5 +1,6 @@ /** * Copyright 2005-2012 Akiban Technologies, Inc. + * Portions Copyrighted 2026 3A Systems, LLC. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -104,7 +105,7 @@ public static void main(String[] args) throws Exception { System.out.println("Completed transactions: " + _committedTransactionCount); System.out.println("Failed transactions: " + _failedTransactionCount); System.out.println("Retried transactions: " + _rolledBackTransactionCount); - System.out.println("Average completed transactions rate: " + (_committedTransactionCount * 1000 / time) + System.out.println("Average completed transactions rate: " + (_committedTransactionCount * 1000L / time) + " per second"); int endingBalance = balance(accountEx); diff --git a/persistit/ui/src/main/java/com/persistit/ui/AdminUI.java b/persistit/ui/src/main/java/com/persistit/ui/AdminUI.java index 5a47719ae6..e3786ff498 100644 --- a/persistit/ui/src/main/java/com/persistit/ui/AdminUI.java +++ b/persistit/ui/src/main/java/com/persistit/ui/AdminUI.java @@ -1,5 +1,6 @@ /** * Copyright 2005-2012 Akiban Technologies, Inc. + * Portions Copyrighted 2026 3A Systems, LLC. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1285,7 +1286,7 @@ public void run() { if (interval >= 0) _refreshInterval = interval; if (_refreshInterval > 0) { - _refreshTimer.schedule(_refreshTimerTask, 0, _refreshInterval * 1000); + _refreshTimer.schedule(_refreshTimerTask, 0, _refreshInterval * 1000L); } else { _refreshTimer.schedule(_refreshTimerTask, 0); }