Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sbrannen opened this issue Jan 20, 2025 · 0 comments
Closed

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

sbrannen opened this issue Jan 20, 2025 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@sbrannen
Copy link
Member

sbrannen commented Jan 20, 2025

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/junit5#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

@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Jan 20, 2025
@sbrannen sbrannen added this to the 7.0.0-M1 milestone Jan 20, 2025
@sbrannen sbrannen self-assigned this Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant