This is an automated email from the ASF dual-hosted git repository.

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


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

commit 2c25cd62ae95a6ec020f1b20fe8ce0f4eb5eb629
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 d26bc13628..d80446deee 100644
--- a/java/org/apache/catalina/tribes/util/LocalStrings.properties
+++ b/java/org/apache/catalina/tribes/util/LocalStrings.properties
@@ -25,4 +25,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);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to