Skip to content

Remove binary array name handling in ClassUtils.forName() #34291

@sbrannen

Description

@sbrannen

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:

// "[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.

Related Issues

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions