From e2f69d040a2af89a11d48ad0b7a1d6d5a2691aa2 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Mon, 27 May 2019 13:38:54 +0900 Subject: [PATCH 1/2] Use actual resolvedType when checking Binder cache Update `JavaBeanBinder` so that the `isOfDifferentType` method checks both the actual type and the resolved type. Prior to this commit, it was possible that when `canCallGetValue` is `true` the `resolvedType` could be different from `type.resolve`. Closes gh-16974 --- .../boot/context/properties/bind/JavaBeanBinder.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/JavaBeanBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/JavaBeanBinder.java index c307c3a56a..f4c8acc08d 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/JavaBeanBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/JavaBeanBinder.java @@ -192,12 +192,12 @@ class JavaBeanBinder implements BeanBinder { }); } - private boolean isOfDifferentType(ResolvableType targetType) { + private boolean isOfDifferentType(ResolvableType targetType, + Class resolvedType) { if (this.type.hasGenerics() || targetType.hasGenerics()) { return !this.type.equals(targetType); } - return this.resolvedType == null - || !this.resolvedType.equals(targetType.resolve()); + return this.resolvedType == null || !this.resolvedType.equals(resolvedType); } @SuppressWarnings("unchecked") @@ -214,7 +214,7 @@ class JavaBeanBinder implements BeanBinder { return null; } Bean bean = Bean.cached; - if (bean == null || bean.isOfDifferentType(type)) { + if (bean == null || bean.isOfDifferentType(type, resolvedType)) { bean = new Bean<>(type, resolvedType); cached = bean; } From 07ebfc036b5ee6aa22cec447938bc48eb8693cbe Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 28 May 2019 13:12:48 -0700 Subject: [PATCH 2/2] Polish --- .../context/properties/bind/JavaBeanBinder.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/JavaBeanBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/JavaBeanBinder.java index f4c8acc08d..65dbcb2910 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/JavaBeanBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/JavaBeanBinder.java @@ -192,14 +192,6 @@ class JavaBeanBinder implements BeanBinder { }); } - private boolean isOfDifferentType(ResolvableType targetType, - Class resolvedType) { - if (this.type.hasGenerics() || targetType.hasGenerics()) { - return !this.type.equals(targetType); - } - return this.resolvedType == null || !this.resolvedType.equals(resolvedType); - } - @SuppressWarnings("unchecked") public static Bean get(Bindable bindable, boolean canCallGetValue) { ResolvableType type = bindable.getType(); @@ -214,7 +206,7 @@ class JavaBeanBinder implements BeanBinder { return null; } Bean bean = Bean.cached; - if (bean == null || bean.isOfDifferentType(type, resolvedType)) { + if (bean == null || !bean.isOfType(type, resolvedType)) { bean = new Bean<>(type, resolvedType); cached = bean; } @@ -234,6 +226,13 @@ class JavaBeanBinder implements BeanBinder { } } + private boolean isOfType(ResolvableType type, Class resolvedType) { + if (this.type.hasGenerics() || type.hasGenerics()) { + return this.type.equals(type); + } + return this.resolvedType != null && this.resolvedType.equals(resolvedType); + } + } private static class BeanSupplier implements Supplier {