From 7fedb9c1d401dd5225d00032d805f97d152d510e Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Mon, 20 Jan 2025 16:16:01 +0100 Subject: [PATCH] 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 --- .../org/springframework/util/ClassUtils.java | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/ClassUtils.java b/spring-core/src/main/java/org/springframework/util/ClassUtils.java index c764d681b7..1e15e291c8 100644 --- a/spring-core/src/main/java/org/springframework/util/ClassUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ClassUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,12 +74,6 @@ public abstract class ClassUtils { /** Suffix for array class names: {@code "[]"}. */ public static final String ARRAY_SUFFIX = "[]"; - /** Prefix for internal array class names: {@code "["}. */ - private static final String INTERNAL_ARRAY_PREFIX = "["; - - /** Prefix for internal non-primitive array class names: {@code "[L"}. */ - private static final String NON_PRIMITIVE_ARRAY_PREFIX = "[L"; - /** A reusable empty class array constant. */ private static final Class[] EMPTY_CLASS_ARRAY = {}; @@ -297,20 +291,6 @@ public abstract class ClassUtils { return elementClass.arrayType(); } - // "[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(); - } - ClassLoader clToUse = classLoader; if (clToUse == null) { clToUse = getDefaultClassLoader();