Skip to content

Commit 7a8d41e

Browse files
committed
Extended set of common classes and language interfaces in ClassUtils
Issue: SPR-16667
1 parent 8dd0974 commit 7a8d41e

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

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

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.util;
1818

1919
import java.beans.Introspector;
20+
import java.io.Closeable;
2021
import java.io.Externalizable;
2122
import java.io.Serializable;
2223
import java.lang.reflect.Array;
@@ -27,12 +28,15 @@
2728
import java.util.Arrays;
2829
import java.util.Collection;
2930
import java.util.Collections;
31+
import java.util.Enumeration;
3032
import java.util.HashMap;
3133
import java.util.HashSet;
3234
import java.util.IdentityHashMap;
3335
import java.util.Iterator;
3436
import java.util.LinkedHashSet;
37+
import java.util.List;
3538
import java.util.Map;
39+
import java.util.Optional;
3640
import java.util.Set;
3741

3842
import org.springframework.lang.Nullable;
@@ -76,13 +80,6 @@ public abstract class ClassUtils {
7680
public static final String CLASS_FILE_SUFFIX = ".class";
7781

7882

79-
/**
80-
* Common Java language interfaces which are supposed to be ignored
81-
* when searching for 'primary' user-level interfaces.
82-
*/
83-
private static final Set<Class<?>> javaLanguageInterfaces = new HashSet<>(
84-
Arrays.asList(Serializable.class, Externalizable.class, Cloneable.class, Comparable.class));
85-
8683
/**
8784
* Map with primitive wrapper type as key and corresponding primitive
8885
* type as value, for example: Integer.class -> int.class.
@@ -102,10 +99,16 @@ public abstract class ClassUtils {
10299
private static final Map<String, Class<?>> primitiveTypeNameMap = new HashMap<>(32);
103100

104101
/**
105-
* Map with common "java.lang" class name as key and corresponding Class as value.
102+
* Map with common Java language class name as key and corresponding Class as value.
106103
* Primarily for efficient deserialization of remote invocations.
107104
*/
108-
private static final Map<String, Class<?>> commonClassCache = new HashMap<>(32);
105+
private static final Map<String, Class<?>> commonClassCache = new HashMap<>(64);
106+
107+
/**
108+
* Common Java language interfaces which are supposed to be ignored
109+
* when searching for 'primary' user-level interfaces.
110+
*/
111+
private static final Set<Class<?>> javaLanguageInterfaces;
109112

110113

111114
static {
@@ -135,9 +138,16 @@ public abstract class ClassUtils {
135138
registerCommonClasses(Boolean[].class, Byte[].class, Character[].class, Double[].class,
136139
Float[].class, Integer[].class, Long[].class, Short[].class);
137140
registerCommonClasses(Number.class, Number[].class, String.class, String[].class,
138-
Object.class, Object[].class, Class.class, Class[].class);
141+
Class.class, Class[].class, Object.class, Object[].class);
139142
registerCommonClasses(Throwable.class, Exception.class, RuntimeException.class,
140143
Error.class, StackTraceElement.class, StackTraceElement[].class);
144+
registerCommonClasses(Enum.class, Iterable.class, Iterator.class, Enumeration.class,
145+
Collection.class, List.class, Set.class, Map.class, Map.Entry.class, Optional.class);
146+
147+
Class<?>[] javaLanguageInterfaceArray = {Serializable.class, Externalizable.class,
148+
Closeable.class, AutoCloseable.class, Cloneable.class, Comparable.class};
149+
registerCommonClasses(javaLanguageInterfaceArray);
150+
javaLanguageInterfaces = new HashSet<>(Arrays.asList(javaLanguageInterfaceArray));
141151
}
142152

143153

@@ -1235,10 +1245,10 @@ public static boolean isVisible(Class<?> clazz, @Nullable ClassLoader classLoade
12351245

12361246
/**
12371247
* Determine whether the given interface is a common Java language interface:
1238-
* {@link Serializable}, {@link Externalizable}, {@link Cloneable}, {@link Comparable}
1239-
* - all of which can be ignored when looking for 'primary' user-level interfaces.
1240-
* Common characteristics: no service-level operations, no bean property methods,
1241-
* no default methods.
1248+
* {@link Serializable}, {@link Externalizable}, {@link Closeable}, {@link AutoCloseable},
1249+
* {@link Cloneable}, {@link Comparable} - all of which can be ignored when looking
1250+
* for 'primary' user-level interfaces. Common characteristics: no service-level
1251+
* operations, no bean property methods, no default methods.
12421252
* @param ifc the interface to check
12431253
* @since 5.0.3
12441254
*/

0 commit comments

Comments
 (0)