Skip to content

Commit 19fb697

Browse files
philwebbjhoeller
authored andcommitted
Add more empty array constants in ReflectionUtils
Add some additional empty array constants to `ReflectionUtils` to save us creating new arrays for zero length results. See gh-22567
1 parent e3a86be commit 19fb697

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,14 @@ public abstract class ReflectionUtils {
6666
*/
6767
private static final String CGLIB_RENAMED_METHOD_PREFIX = "CGLIB$";
6868

69+
private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[0];
70+
6971
private static final Method[] EMPTY_METHOD_ARRAY = new Method[0];
7072

7173
private static final Field[] EMPTY_FIELD_ARRAY = new Field[0];
7274

75+
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
76+
7377

7478
/**
7579
* Cache for {@link Class#getDeclaredMethods()} plus equivalent default methods
@@ -211,7 +215,7 @@ public static void makeAccessible(Constructor<?> ctor) {
211215
*/
212216
@Nullable
213217
public static Method findMethod(Class<?> clazz, String name) {
214-
return findMethod(clazz, name, new Class<?>[0]);
218+
return findMethod(clazz, name, EMPTY_CLASS_ARRAY);
215219
}
216220

217221
/**
@@ -255,7 +259,7 @@ public static Method findMethod(Class<?> clazz, String name, @Nullable Class<?>.
255259
*/
256260
@Nullable
257261
public static Object invokeMethod(Method method, @Nullable Object target) {
258-
return invokeMethod(method, target, new Object[0]);
262+
return invokeMethod(method, target, EMPTY_OBJECT_ARRAY);
259263
}
260264

261265
/**

0 commit comments

Comments
 (0)