Skip to content

Commit 8036435

Browse files
committed
Merge branch '5.1.x'
2 parents 0c73599 + d036b5a commit 8036435

File tree

3 files changed

+93
-23
lines changed

3 files changed

+93
-23
lines changed

spring-beans/src/main/java/org/springframework/beans/BeanUtils.java

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -583,36 +583,43 @@ public static MethodParameter getWriteMethodParameter(PropertyDescriptor pd) {
583583
}
584584

585585
/**
586-
* Check if the given type represents a "simple" property:
587-
* a primitive, a String or other CharSequence, a Number, a Date,
588-
* a Temporal, a URI, a URL, a Locale, a Class, or a corresponding array.
586+
* Check if the given type represents a "simple" property: a simple value
587+
* type or an array of simple value types.
588+
* <p>See {@link #isSimpleValueType(Class)} for the definition of <em>simple
589+
* value type</em>.
589590
* <p>Used to determine properties to check for a "simple" dependency-check.
590-
* @param clazz the type to check
591+
* @param type the type to check
591592
* @return whether the given type represents a "simple" property
592593
* @see org.springframework.beans.factory.support.RootBeanDefinition#DEPENDENCY_CHECK_SIMPLE
593594
* @see org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#checkDependencies
595+
* @see #isSimpleValueType(Class)
594596
*/
595-
public static boolean isSimpleProperty(Class<?> clazz) {
596-
Assert.notNull(clazz, "Class must not be null");
597-
return isSimpleValueType(clazz) || (clazz.isArray() && isSimpleValueType(clazz.getComponentType()));
597+
public static boolean isSimpleProperty(Class<?> type) {
598+
Assert.notNull(type, "'type' must not be null");
599+
return isSimpleValueType(type) || (type.isArray() && isSimpleValueType(type.getComponentType()));
598600
}
599601

600602
/**
601-
* Check if the given type represents a "simple" value type:
602-
* a primitive, an enum, a String or other CharSequence, a Number, a Date,
603-
* a Temporal, a URI, a URL, a Locale or a Class.
604-
* @param clazz the type to check
603+
* Check if the given type represents a "simple" value type: a primitive or
604+
* primitive wrapper, an enum, a String or other CharSequence, a Number, a
605+
* Date, a Temporal, a URI, a URL, a Locale, or a Class.
606+
* <p>{@code Void} and {@code void} are not considered simple value types.
607+
* @param type the type to check
605608
* @return whether the given type represents a "simple" value type
609+
* @see #isSimpleProperty(Class)
606610
*/
607-
public static boolean isSimpleValueType(Class<?> clazz) {
608-
return (ClassUtils.isPrimitiveOrWrapper(clazz) ||
609-
Enum.class.isAssignableFrom(clazz) ||
610-
CharSequence.class.isAssignableFrom(clazz) ||
611-
Number.class.isAssignableFrom(clazz) ||
612-
Date.class.isAssignableFrom(clazz) ||
613-
Temporal.class.isAssignableFrom(clazz) ||
614-
URI.class == clazz || URL.class == clazz ||
615-
Locale.class == clazz || Class.class == clazz);
611+
public static boolean isSimpleValueType(Class<?> type) {
612+
return (type != void.class && type != Void.class &&
613+
(ClassUtils.isPrimitiveOrWrapper(type) ||
614+
Enum.class.isAssignableFrom(type) ||
615+
CharSequence.class.isAssignableFrom(type) ||
616+
Number.class.isAssignableFrom(type) ||
617+
Date.class.isAssignableFrom(type) ||
618+
Temporal.class.isAssignableFrom(type) ||
619+
URI.class == type ||
620+
URL.class == type ||
621+
Locale.class == type ||
622+
Class.class == type));
616623
}
617624

618625

spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020
import java.beans.PropertyDescriptor;
2121
import java.lang.reflect.Constructor;
2222
import java.lang.reflect.Method;
23+
import java.net.URI;
24+
import java.net.URL;
25+
import java.time.DayOfWeek;
26+
import java.util.Date;
2327
import java.util.List;
28+
import java.util.Locale;
29+
import java.util.stream.Stream;
2430

2531
import org.junit.jupiter.api.Test;
2632

@@ -44,6 +50,7 @@
4450
* @author Rob Harrop
4551
* @author Chris Beams
4652
* @author Sebastien Deleuze
53+
* @author Sam Brannen
4754
* @since 19.05.2003
4855
*/
4956
public class BeanUtilsTests {
@@ -285,6 +292,60 @@ public void testSPR6063() {
285292
}
286293
}
287294

295+
@Test
296+
public void isSimpleValueType() {
297+
Stream.of(
298+
299+
boolean.class, char.class, byte.class, short.class, int.class,
300+
long.class, float.class, double.class,
301+
302+
Boolean.class, Character.class, Byte.class, Short.class, Integer.class,
303+
Long.class, Float.class, Double.class,
304+
305+
DayOfWeek.class, String.class, Date.class, URI.class, URL.class, Locale.class, Class.class
306+
307+
).forEach(this::assertIsSimpleValueType);
308+
309+
Stream.of(int[].class, Object.class, List.class, void.class, Void.class)
310+
.forEach(this::assertIsNotSimpleValueType);
311+
}
312+
313+
@Test
314+
public void isSimpleProperty() {
315+
Stream.of(
316+
317+
boolean.class, char.class, byte.class, short.class, int.class,
318+
long.class, float.class, double.class,
319+
320+
Boolean.class, Character.class, Byte.class, Short.class, Integer.class,
321+
Long.class, Float.class, Double.class,
322+
323+
DayOfWeek.class, String.class, Date.class, URI.class, URL.class, Locale.class, Class.class,
324+
325+
boolean[].class, Boolean[].class, Date[].class
326+
327+
).forEach(this::assertIsSimpleProperty);
328+
329+
Stream.of(Object.class, List.class, void.class, Void.class)
330+
.forEach(this::assertIsNotSimpleProperty);
331+
}
332+
333+
private void assertIsSimpleValueType(Class<?> type) {
334+
assertThat(BeanUtils.isSimpleValueType(type)).as("Type [" + type.getName() + "] should be a simple value type").isTrue();
335+
}
336+
337+
private void assertIsNotSimpleValueType(Class<?> type) {
338+
assertThat(BeanUtils.isSimpleValueType(type)).as("Type [" + type.getName() + "] should not be a simple value type").isFalse();
339+
}
340+
341+
private void assertIsSimpleProperty(Class<?> type) {
342+
assertThat(BeanUtils.isSimpleProperty(type)).as("Type [" + type.getName() + "] should be a simple property").isTrue();
343+
}
344+
345+
private void assertIsNotSimpleProperty(Class<?> type) {
346+
assertThat(BeanUtils.isSimpleProperty(type)).as("Type [" + type.getName() + "] should not be a simple property").isFalse();
347+
}
348+
288349
private void assertSignatureEquals(Method desiredMethod, String signature) {
289350
assertThat(BeanUtils.resolveSignature(signature, MethodSignatureBean.class)).isEqualTo(desiredMethod);
290351
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,11 @@ public boolean supports(HandlerResult result) {
160160
type = result.getReturnType().getGeneric().toClass();
161161
}
162162

163-
return (CharSequence.class.isAssignableFrom(type) || Rendering.class.isAssignableFrom(type) ||
164-
Model.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type) ||
165-
void.class == type || Void.class == type || View.class.isAssignableFrom(type) ||
163+
return (CharSequence.class.isAssignableFrom(type) ||
164+
Rendering.class.isAssignableFrom(type) ||
165+
Model.class.isAssignableFrom(type) ||
166+
Map.class.isAssignableFrom(type) ||
167+
View.class.isAssignableFrom(type) ||
166168
!BeanUtils.isSimpleProperty(type));
167169
}
168170

0 commit comments

Comments
 (0)