From 75f4d9e3fdad11055243b6ec30e0760076a69b7a Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 30 Sep 2022 21:16:48 -0700 Subject: [PATCH] Fix empty @DefaultValue annotation test failures on Java 17 See gh-32559 --- .../context/properties/bind/ValueObjectBinder.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/ValueObjectBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/ValueObjectBinder.java index e6736155bc2f..c6378d4bd8af 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/ValueObjectBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/ValueObjectBinder.java @@ -131,10 +131,6 @@ private T getNewDefaultValueInstanceIfPossible(Binder.Context context, Resol Class resolved = (Class) type.resolve(); Assert.state(resolved == null || isEmptyDefaultValueAllowed(resolved), () -> "Parameter of type " + type + " must have a non-empty default value."); - T instance = create(Bindable.of(type), context); - if (instance != null) { - return instance; - } if (resolved != null) { if (Optional.class == resolved) { return (T) Optional.empty(); @@ -148,9 +144,12 @@ private T getNewDefaultValueInstanceIfPossible(Binder.Context context, Resol if (resolved.isArray()) { return (T) Array.newInstance(resolved.getComponentType(), 0); } - return BeanUtils.instantiateClass(resolved); } - return null; + T instance = create(Bindable.of(type), context); + if (instance != null) { + return instance; + } + return (resolved != null) ? BeanUtils.instantiateClass(resolved) : null; } private boolean isEmptyDefaultValueAllowed(Class type) {