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

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ffb33634 [LANG-1830] Avoid repeated regex compilation in 
ClassUtils.toCleanName() (#1754)
2ffb33634 is described below

commit 2ffb336343b1a8ee7ac8a4bf35433331da17c98b
Author: Maksym Korshun <[email protected]>
AuthorDate: Mon Jul 27 00:44:44 2026 +0200

    [LANG-1830] Avoid repeated regex compilation in ClassUtils.toCleanName() 
(#1754)
---
 src/main/java/org/apache/commons/lang3/ClassUtils.java | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java 
b/src/main/java/org/apache/commons/lang3/ClassUtils.java
index e2f19cf56..fd75e1732 100644
--- a/src/main/java/org/apache/commons/lang3/ClassUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java
@@ -32,6 +32,7 @@
 import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 /**
@@ -89,6 +90,8 @@ public enum Interfaces {
      */
     private static final int MAX_DIMENSIONS = 255;
 
+    private static final Pattern ARRAY_TAIL_PATTERN = 
Pattern.compile("(?:\\[\\])+");
+
     private static final Comparator<Class<?>> COMPARATOR = (o1, o2) -> 
Objects.compare(getName(o1), getName(o2), String::compareTo);
 
     /**
@@ -1647,7 +1650,7 @@ private static String toCleanName(final String className) 
{
             // "java.lang.String[]][]" where the suffix is not composed of
             // repeated "[]" pairs.
             final String tail = canonicalName.substring(arrIdx);
-            if (!tail.matches("(?:\\[\\])+")) {
+            if (!ARRAY_TAIL_PATTERN.matcher(tail).matches()) {
                 throw new IllegalArgumentException("Malformed array name: " + 
canonicalName);
             }
             final int dims =  (canonicalName.length() - arrIdx) / 2;

Reply via email to