Extended set of common classes and language interfaces in ClassUtils
Issue: SPR-16667
This commit is contained in:
parent
8dd0974e2f
commit
7a8d41e5d6
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.util;
|
||||
|
||||
import java.beans.Introspector;
|
||||
import java.io.Closeable;
|
||||
import java.io.Externalizable;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Array;
|
||||
|
|
@ -27,12 +28,15 @@ import java.lang.reflect.Proxy;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
|
@ -76,13 +80,6 @@ public abstract class ClassUtils {
|
|||
public static final String CLASS_FILE_SUFFIX = ".class";
|
||||
|
||||
|
||||
/**
|
||||
* Common Java language interfaces which are supposed to be ignored
|
||||
* when searching for 'primary' user-level interfaces.
|
||||
*/
|
||||
private static final Set<Class<?>> javaLanguageInterfaces = new HashSet<>(
|
||||
Arrays.asList(Serializable.class, Externalizable.class, Cloneable.class, Comparable.class));
|
||||
|
||||
/**
|
||||
* Map with primitive wrapper type as key and corresponding primitive
|
||||
* type as value, for example: Integer.class -> int.class.
|
||||
|
|
@ -102,10 +99,16 @@ public abstract class ClassUtils {
|
|||
private static final Map<String, Class<?>> primitiveTypeNameMap = new HashMap<>(32);
|
||||
|
||||
/**
|
||||
* Map with common "java.lang" class name as key and corresponding Class as value.
|
||||
* Map with common Java language class name as key and corresponding Class as value.
|
||||
* Primarily for efficient deserialization of remote invocations.
|
||||
*/
|
||||
private static final Map<String, Class<?>> commonClassCache = new HashMap<>(32);
|
||||
private static final Map<String, Class<?>> commonClassCache = new HashMap<>(64);
|
||||
|
||||
/**
|
||||
* Common Java language interfaces which are supposed to be ignored
|
||||
* when searching for 'primary' user-level interfaces.
|
||||
*/
|
||||
private static final Set<Class<?>> javaLanguageInterfaces;
|
||||
|
||||
|
||||
static {
|
||||
|
|
@ -135,9 +138,16 @@ public abstract class ClassUtils {
|
|||
registerCommonClasses(Boolean[].class, Byte[].class, Character[].class, Double[].class,
|
||||
Float[].class, Integer[].class, Long[].class, Short[].class);
|
||||
registerCommonClasses(Number.class, Number[].class, String.class, String[].class,
|
||||
Object.class, Object[].class, Class.class, Class[].class);
|
||||
Class.class, Class[].class, Object.class, Object[].class);
|
||||
registerCommonClasses(Throwable.class, Exception.class, RuntimeException.class,
|
||||
Error.class, StackTraceElement.class, StackTraceElement[].class);
|
||||
registerCommonClasses(Enum.class, Iterable.class, Iterator.class, Enumeration.class,
|
||||
Collection.class, List.class, Set.class, Map.class, Map.Entry.class, Optional.class);
|
||||
|
||||
Class<?>[] javaLanguageInterfaceArray = {Serializable.class, Externalizable.class,
|
||||
Closeable.class, AutoCloseable.class, Cloneable.class, Comparable.class};
|
||||
registerCommonClasses(javaLanguageInterfaceArray);
|
||||
javaLanguageInterfaces = new HashSet<>(Arrays.asList(javaLanguageInterfaceArray));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1235,10 +1245,10 @@ public abstract class ClassUtils {
|
|||
|
||||
/**
|
||||
* Determine whether the given interface is a common Java language interface:
|
||||
* {@link Serializable}, {@link Externalizable}, {@link Cloneable}, {@link Comparable}
|
||||
* - all of which can be ignored when looking for 'primary' user-level interfaces.
|
||||
* Common characteristics: no service-level operations, no bean property methods,
|
||||
* no default methods.
|
||||
* {@link Serializable}, {@link Externalizable}, {@link Closeable}, {@link AutoCloseable},
|
||||
* {@link Cloneable}, {@link Comparable} - all of which can be ignored when looking
|
||||
* for 'primary' user-level interfaces. Common characteristics: no service-level
|
||||
* operations, no bean property methods, no default methods.
|
||||
* @param ifc the interface to check
|
||||
* @since 5.0.3
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue