-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Overview
For a bit of background, we seem to have flipped back and forth between using Class.forName()
and ClassLoader.loadClass()
over the years, but in Spring Framework 5.1.1 we switched from ClassLoader.loadClass()
to Class.forName()
in ClassUtils.forName()
(see #21867).
Thanks to a discovery made by @sormuras (see junit-team/junit-framework#4250), I have learned that Class.forName()
has built-in support for binary array names; whereas, ClassLoader.loadClass()
does not.
In light of that, we should be able to remove the following custom support for binary array names:
spring-framework/spring-core/src/main/java/org/springframework/util/ClassUtils.java
Lines 300 to 312 in eda7af7
// "[Ljava.lang.String;" style arrays | |
if (name.startsWith(NON_PRIMITIVE_ARRAY_PREFIX) && name.endsWith(";")) { | |
String elementName = name.substring(NON_PRIMITIVE_ARRAY_PREFIX.length(), name.length() - 1); | |
Class<?> elementClass = forName(elementName, classLoader); | |
return elementClass.arrayType(); | |
} | |
// "[[I" or "[[Ljava.lang.String;" style arrays | |
if (name.startsWith(INTERNAL_ARRAY_PREFIX)) { | |
String elementName = name.substring(INTERNAL_ARRAY_PREFIX.length()); | |
Class<?> elementClass = forName(elementName, classLoader); | |
return elementClass.arrayType(); | |
} |
I removed that and tested locally in Eclipse and with a full Gradle build, and all tests pass.