Skip to content

Commit 7fedb9c

Browse files
committed
Remove binary array name handling in ClassUtils.forName()
In ClassUtils.forName(), we originally delegated to ClassLoader.loadClass(), which does not support loading classes from binary names for arrays (such as "[[I" for "int[][]" or "[Ljava.lang.String;" for "String[]"); whereas, Class.forName() does support binary names for arrays. However, in Spring Framework 5.1.1 we switched from using ClassLoader.loadClass() to Class.forName() in ClassUtils.forName() (see gh-21867), which makes our custom handling of binary names for arrays in ClassUtils.forName() obsolete. In light of that, this commit removes our custom binary array name handling support from ClassUtils.forName(). Closes gh-34291
1 parent eda7af7 commit 7fedb9c

File tree

1 file changed

+1
-21
lines changed

1 file changed

+1
-21
lines changed

spring-core/src/main/java/org/springframework/util/ClassUtils.java

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -74,12 +74,6 @@ public abstract class ClassUtils {
7474
/** Suffix for array class names: {@code "[]"}. */
7575
public static final String ARRAY_SUFFIX = "[]";
7676

77-
/** Prefix for internal array class names: {@code "["}. */
78-
private static final String INTERNAL_ARRAY_PREFIX = "[";
79-
80-
/** Prefix for internal non-primitive array class names: {@code "[L"}. */
81-
private static final String NON_PRIMITIVE_ARRAY_PREFIX = "[L";
82-
8377
/** A reusable empty class array constant. */
8478
private static final Class<?>[] EMPTY_CLASS_ARRAY = {};
8579

@@ -297,20 +291,6 @@ public static Class<?> forName(String name, @Nullable ClassLoader classLoader)
297291
return elementClass.arrayType();
298292
}
299293

300-
// "[Ljava.lang.String;" style arrays
301-
if (name.startsWith(NON_PRIMITIVE_ARRAY_PREFIX) && name.endsWith(";")) {
302-
String elementName = name.substring(NON_PRIMITIVE_ARRAY_PREFIX.length(), name.length() - 1);
303-
Class<?> elementClass = forName(elementName, classLoader);
304-
return elementClass.arrayType();
305-
}
306-
307-
// "[[I" or "[[Ljava.lang.String;" style arrays
308-
if (name.startsWith(INTERNAL_ARRAY_PREFIX)) {
309-
String elementName = name.substring(INTERNAL_ARRAY_PREFIX.length());
310-
Class<?> elementClass = forName(elementName, classLoader);
311-
return elementClass.arrayType();
312-
}
313-
314294
ClassLoader clToUse = classLoader;
315295
if (clToUse == null) {
316296
clToUse = getDefaultClassLoader();

0 commit comments

Comments
 (0)