Consider Void.class a primitive wrapper in ClassUtils
Prior to this commit, ClassUtils.isPrimitiveOrWrapper() and ClassUtils.isPrimitiveWrapper() did not return true for Void.class. However, ClassUtils.isPrimitiveOrWrapper() did return true for void.class. This lacking symmetry is inconsistent and can lead to bugs in reflective code. See: https://github.com/spring-projects/spring-data-r2dbc/issues/159 This commit addresses this by adding an entry for Void.class -> void.class in the internal primitiveWrapperTypeMap in ClassUtils. Closes gh-23572
This commit is contained in:
@@ -120,6 +120,7 @@ public abstract class ClassUtils {
|
||||
primitiveWrapperTypeMap.put(Integer.class, int.class);
|
||||
primitiveWrapperTypeMap.put(Long.class, long.class);
|
||||
primitiveWrapperTypeMap.put(Short.class, short.class);
|
||||
primitiveWrapperTypeMap.put(Void.class, void.class);
|
||||
|
||||
// Map entry iteration is less expensive to initialize than forEach with lambdas
|
||||
for (Map.Entry<Class<?>, Class<?>> entry : primitiveWrapperTypeMap.entrySet()) {
|
||||
@@ -462,7 +463,8 @@ public abstract class ClassUtils {
|
||||
|
||||
/**
|
||||
* Check if the given class represents a primitive wrapper,
|
||||
* i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
|
||||
* i.e. Boolean, Byte, Character, Short, Integer, Long, Float, Double, or
|
||||
* Void.
|
||||
* @param clazz the class to check
|
||||
* @return whether the given class is a primitive wrapper class
|
||||
*/
|
||||
@@ -473,10 +475,12 @@ public abstract class ClassUtils {
|
||||
|
||||
/**
|
||||
* Check if the given class represents a primitive (i.e. boolean, byte,
|
||||
* char, short, int, long, float, or double) or a primitive wrapper
|
||||
* (i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double).
|
||||
* char, short, int, long, float, or double), {@code void}, or a wrapper for
|
||||
* those types (i.e. Boolean, Byte, Character, Short, Integer, Long, Float,
|
||||
* Double, or Void).
|
||||
* @param clazz the class to check
|
||||
* @return whether the given class is a primitive or primitive wrapper class
|
||||
* @return {@code true} if the given class represents a primitive, void, or
|
||||
* a wrapper class
|
||||
*/
|
||||
public static boolean isPrimitiveOrWrapper(Class<?> clazz) {
|
||||
Assert.notNull(clazz, "Class must not be null");
|
||||
|
||||
Reference in New Issue
Block a user