(tomcat) branch main updated: Avoid IDE warning. Detect invalid offset. Better exception messages.

[email protected] Fri, 10 Jul 2026 09:46:18 +0000
Newsgroups gmane.comp.jakarta.tomcat.devel
Message-ID <178367677809.2722289.9739105258357173487@gitbox3-he-fi.apache.org>
This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 81916e0adf Avoid IDE warning. Detect invalid offset. Better exception messages.
81916e0adf is described below

commit 81916e0adf5f8f716b5c96d774ce037183455e67
Author: Mark Thomas <[email protected]>
AuthorDate: Fri Jul 10 10:46:05 2026 +0100

    Avoid IDE warning. Detect invalid offset. Better exception messages.
---
 .../apache/catalina/tribes/util/LocalStrings.properties    |  2 ++
 java/org/apache/catalina/tribes/util/UUIDGenerator.java    | 14 ++++++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/catalina/tribes/util/LocalStrings.properties b/java/org/apache/catalina/tribes/util/LocalStrings.properties
index 4238fab4ac..013a76dc8d 100644
--- a/java/org/apache/catalina/tribes/util/LocalStrings.properties
+++ b/java/org/apache/catalina/tribes/util/LocalStrings.properties
@@ -22,4 +22,6 @@ executorFactory.not.running=Executor not running, can't force a command into the
 executorFactory.queue.full=Queue capacity is full.
 
 uuidGenerator.createRandom=Creation of SecureRandom instance for UUID generation using [{0}] took [{1}] milliseconds.
+uuidGenerator.dest.null=The provided destination array is null
+uuidGenerator.offset.negative=The offset in the destination byte array is negative
 uuidGenerator.unable.fit=Unable to fit [{0}] bytes into the array. length:[{1}] required length:[{2}]
diff --git a/java/org/apache/catalina/tribes/util/UUIDGenerator.java b/java/org/apache/catalina/tribes/util/UUIDGenerator.java
index 6f78b57117..f23363314f 100644
--- a/java/org/apache/catalina/tribes/util/UUIDGenerator.java
+++ b/java/org/apache/catalina/tribes/util/UUIDGenerator.java
@@ -96,14 +96,20 @@ public class UUIDGenerator {
      *
      * @return The byte array containing the UUID
      *
-     * @throws ArrayIndexOutOfBoundsException If the byte array is too small or null
+     * @throws ArrayIndexOutOfBoundsException If the destination byte array is null, the destination byte array is too
+     *                                            small or the offset is negative
      */
     public static byte[] randomUUID(boolean secure, byte[] dest, int offset) {
-        int destLength = (dest == null) ? 0 : dest.length;
-        if ((offset + UUID_LENGTH) > destLength) {
+        if (offset < 0) {
+            throw new ArrayIndexOutOfBoundsException(sm.getString("uuidGenerator.offset.negative"));
+        }
+        if (dest == null) {
+            throw new ArrayIndexOutOfBoundsException(sm.getString("uuidGenerator.dest.null"));
+        }
+        if ((offset + UUID_LENGTH) > dest.length) {
             throw new ArrayIndexOutOfBoundsException(
                     sm.getString("uuidGenerator.unable.fit", Integer.toString(UUID_LENGTH),
-                            Integer.toString(destLength), Integer.toString(offset + UUID_LENGTH)));
+                            Integer.toString(dest.length), Integer.toString(offset + UUID_LENGTH)));
         }
         Random r = (secure && (secrand != null)) ? secrand : rand;
         nextBytes(dest, offset, UUID_LENGTH, r);