(tomcat) branch 10.1.x updated: Avoid IDE warning. Detect invalid offset. Better exception messages.
[email protected] Fri, 10 Jul 2026 09:46:25 +0000
| Newsgroups | gmane.comp.jakarta.tomcat.devel |
|---|---|
| Message-ID | <178367678593.2723008.13471474401467015279@gitbox3-he-fi.apache.org> |
This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 33be7b018e Avoid IDE warning. Detect invalid offset. Better exception messages.
33be7b018e is described below
commit 33be7b018e9ad41e5bf365dccf85fea6ffb0f3bf
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 8b7d800194..2e3db59989 100644
--- a/java/org/apache/catalina/tribes/util/LocalStrings.properties
+++ b/java/org/apache/catalina/tribes/util/LocalStrings.properties
@@ -27,4 +27,6 @@ executorFactory.queue.full=Queue capacity is full.
jre14Compat.javaPre14=Class not found so assuming code is running on a pre-Java 14 JVM
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);