Skip to content

Commit c78960a

Browse files
committed
Merge branch '5.1.x'
2 parents 32a585d + f37ec90 commit c78960a

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public abstract class ClassUtils {
121121
primitiveWrapperTypeMap.put(Integer.class, int.class);
122122
primitiveWrapperTypeMap.put(Long.class, long.class);
123123
primitiveWrapperTypeMap.put(Short.class, short.class);
124+
primitiveWrapperTypeMap.put(Void.class, void.class);
124125

125126
// Map entry iteration is less expensive to initialize than forEach with lambdas
126127
for (Map.Entry<Class<?>, Class<?>> entry : primitiveWrapperTypeMap.entrySet()) {
@@ -463,7 +464,8 @@ public static Class<?> resolvePrimitiveClassName(@Nullable String name) {
463464

464465
/**
465466
* Check if the given class represents a primitive wrapper,
466-
* i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
467+
* i.e. Boolean, Byte, Character, Short, Integer, Long, Float, Double, or
468+
* Void.
467469
* @param clazz the class to check
468470
* @return whether the given class is a primitive wrapper class
469471
*/
@@ -474,10 +476,12 @@ public static boolean isPrimitiveWrapper(Class<?> clazz) {
474476

475477
/**
476478
* Check if the given class represents a primitive (i.e. boolean, byte,
477-
* char, short, int, long, float, or double) or a primitive wrapper
478-
* (i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double).
479+
* char, short, int, long, float, or double), {@code void}, or a wrapper for
480+
* those types (i.e. Boolean, Byte, Character, Short, Integer, Long, Float,
481+
* Double, or Void).
479482
* @param clazz the class to check
480-
* @return whether the given class is a primitive or primitive wrapper class
483+
* @return {@code true} if the given class represents a primitive, void, or
484+
* a wrapper class
481485
*/
482486
public static boolean isPrimitiveOrWrapper(Class<?> clazz) {
483487
Assert.notNull(clazz, "Class must not be null");

spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@
4040
import static org.assertj.core.api.Assertions.assertThat;
4141

4242
/**
43+
* Unit tests for {@link ClassUtils}.
44+
*
4345
* @author Colin Sampaleanu
4446
* @author Juergen Hoeller
4547
* @author Rob Harrop
4648
* @author Rick Evans
49+
* @author Sam Brannen
4750
*/
4851
class ClassUtilsTests {
4952

50-
private ClassLoader classLoader = getClass().getClassLoader();
53+
private final ClassLoader classLoader = getClass().getClassLoader();
5154

5255

5356
@BeforeEach
@@ -380,6 +383,42 @@ void determineCommonAncestor() {
380383
assertThat(ClassUtils.determineCommonAncestor(String.class, List.class)).isNull();
381384
}
382385

386+
@Test
387+
public void isPrimitiveWrapper() {
388+
assertThat(ClassUtils.isPrimitiveWrapper(Boolean.class)).isTrue();
389+
assertThat(ClassUtils.isPrimitiveWrapper(Character.class)).isTrue();
390+
assertThat(ClassUtils.isPrimitiveWrapper(Byte.class)).isTrue();
391+
assertThat(ClassUtils.isPrimitiveWrapper(Short.class)).isTrue();
392+
assertThat(ClassUtils.isPrimitiveWrapper(Integer.class)).isTrue();
393+
assertThat(ClassUtils.isPrimitiveWrapper(Long.class)).isTrue();
394+
assertThat(ClassUtils.isPrimitiveWrapper(Float.class)).isTrue();
395+
assertThat(ClassUtils.isPrimitiveWrapper(Double.class)).isTrue();
396+
assertThat(ClassUtils.isPrimitiveWrapper(Void.class)).isTrue();
397+
}
398+
399+
@Test
400+
public void isPrimitiveOrWrapper() {
401+
assertThat(ClassUtils.isPrimitiveOrWrapper(boolean.class)).isTrue();
402+
assertThat(ClassUtils.isPrimitiveOrWrapper(char.class)).isTrue();
403+
assertThat(ClassUtils.isPrimitiveOrWrapper(byte.class)).isTrue();
404+
assertThat(ClassUtils.isPrimitiveOrWrapper(short.class)).isTrue();
405+
assertThat(ClassUtils.isPrimitiveOrWrapper(int.class)).isTrue();
406+
assertThat(ClassUtils.isPrimitiveOrWrapper(long.class)).isTrue();
407+
assertThat(ClassUtils.isPrimitiveOrWrapper(float.class)).isTrue();
408+
assertThat(ClassUtils.isPrimitiveOrWrapper(double.class)).isTrue();
409+
assertThat(ClassUtils.isPrimitiveOrWrapper(void.class)).isTrue();
410+
411+
assertThat(ClassUtils.isPrimitiveOrWrapper(Boolean.class)).isTrue();
412+
assertThat(ClassUtils.isPrimitiveOrWrapper(Character.class)).isTrue();
413+
assertThat(ClassUtils.isPrimitiveOrWrapper(Byte.class)).isTrue();
414+
assertThat(ClassUtils.isPrimitiveOrWrapper(Short.class)).isTrue();
415+
assertThat(ClassUtils.isPrimitiveOrWrapper(Integer.class)).isTrue();
416+
assertThat(ClassUtils.isPrimitiveOrWrapper(Long.class)).isTrue();
417+
assertThat(ClassUtils.isPrimitiveOrWrapper(Float.class)).isTrue();
418+
assertThat(ClassUtils.isPrimitiveOrWrapper(Double.class)).isTrue();
419+
assertThat(ClassUtils.isPrimitiveOrWrapper(Void.class)).isTrue();
420+
}
421+
383422

384423
public static class InnerClass {
385424

spring-webflux/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public boolean supports(HandlerResult result) {
162162

163163
return (CharSequence.class.isAssignableFrom(type) || Rendering.class.isAssignableFrom(type) ||
164164
Model.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type) ||
165-
void.class.equals(type) || View.class.isAssignableFrom(type) ||
165+
Void.class.equals(type) || void.class.equals(type) || View.class.isAssignableFrom(type) ||
166166
!BeanUtils.isSimpleProperty(type));
167167
}
168168

spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ private void testDoesNotSupport(MethodParameter returnType) {
114114
private void testSupports(MethodParameter returnType, boolean supports) {
115115
ViewResolutionResultHandler resultHandler = resultHandler(mock(ViewResolver.class));
116116
HandlerResult handlerResult = new HandlerResult(new Object(), null, returnType, this.bindingContext);
117-
assertThat(resultHandler.supports(handlerResult)).isEqualTo(supports);
117+
if (supports) {
118+
assertThat(resultHandler.supports(handlerResult)).as("return type [" + returnType + "] should be supported").isEqualTo(supports);
119+
}
120+
else {
121+
assertThat(resultHandler.supports(handlerResult)).as("return type [" + returnType + "] should not be supported").isNotEqualTo(supports);
122+
}
118123
}
119124

120125
@Test

0 commit comments

Comments
 (0)