inponomarev commented on code in PR #1591:
URL: https://github.com/apache/commons-lang/pull/1591#discussion_r2737305015
##########
src/main/java/org/apache/commons/lang3/ClassUtils.java:
##########
@@ -1024,17 +1021,37 @@ public static String getShortClassName(final Class<?>
cls) {
if (cls == null) {
return StringUtils.EMPTY;
}
- return getShortClassName(cls.getName());
+ int dim = 0;
+ Class<?> c = cls;
+ while (c.isArray()) {
+ dim++;
+ c = c.getComponentType();
+ }
+
+ final String base;
+ // Preserve legacy behavior for anonymous/local classes (keeps
compiler ordinals: $13, $10Named, etc.)
+ if (c.isAnonymousClass() || c.isLocalClass()) {
+ base = getShortClassName(c.getName());
+ } else {
+ final Deque<String> parts = new ArrayDeque<>();
+ Class<?> x = c;
+ while (x != null) {
+ parts.push(x.getSimpleName());
+ x = x.getDeclaringClass();
+ }
+ base = String.join(String.valueOf(PACKAGE_SEPARATOR_CHAR), parts);
+ }
+
+ final StringBuilder sb = new StringBuilder(base);
+ for (int i = 0; i < dim; i++) {
Review Comment:
done, indeed, why not `StringUtils.repeat()`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]