From 92cf7f1a7f167899085a0fe3c988416723e21a61 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Fri, 5 May 2023 00:10:42 +0900 Subject: [PATCH 1/2] Introduce internal constants for implicit bounds in TypeUtils See gh-30423 --- .../java/org/springframework/util/TypeUtils.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/TypeUtils.java b/spring-core/src/main/java/org/springframework/util/TypeUtils.java index 6f0964d7b1a9..c9e902bcd2be 100644 --- a/spring-core/src/main/java/org/springframework/util/TypeUtils.java +++ b/spring-core/src/main/java/org/springframework/util/TypeUtils.java @@ -36,6 +36,9 @@ */ public abstract class TypeUtils { + private static final Type[] IMPLICIT_LOWER_BOUNDS = { null }; + private static final Type[] IMPLICIT_UPPER_BOUNDS = { Object.class }; + /** * Check if the right-hand side type may be assigned to the left-hand side * type following the Java generics rules. @@ -196,20 +199,14 @@ private static Type[] getLowerBounds(WildcardType wildcardType) { Type[] lowerBounds = wildcardType.getLowerBounds(); // supply the implicit lower bound if none are specified - if (lowerBounds.length == 0) { - lowerBounds = new Type[] { null }; - } - return lowerBounds; + return (lowerBounds.length == 0 ? IMPLICIT_LOWER_BOUNDS : lowerBounds); } private static Type[] getUpperBounds(WildcardType wildcardType) { Type[] upperBounds = wildcardType.getUpperBounds(); // supply the implicit upper bound if none are specified - if (upperBounds.length == 0) { - upperBounds = new Type[] { Object.class }; - } - return upperBounds; + return (upperBounds.length == 0 ? IMPLICIT_UPPER_BOUNDS : upperBounds); } public static boolean isAssignableBound(@Nullable Type lhsType, @Nullable Type rhsType) { From 88361a4f3e4eedbd7a00163945ebf4faf01d36fc Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 5 May 2023 15:01:46 +0200 Subject: [PATCH 2/2] Polish "Introduce internal constants for implicit bounds in TypeUtils" See gh-30423 --- .../src/main/java/org/springframework/util/TypeUtils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-core/src/main/java/org/springframework/util/TypeUtils.java b/spring-core/src/main/java/org/springframework/util/TypeUtils.java index c9e902bcd2be..70e2e5a857cd 100644 --- a/spring-core/src/main/java/org/springframework/util/TypeUtils.java +++ b/spring-core/src/main/java/org/springframework/util/TypeUtils.java @@ -37,6 +37,7 @@ public abstract class TypeUtils { private static final Type[] IMPLICIT_LOWER_BOUNDS = { null }; + private static final Type[] IMPLICIT_UPPER_BOUNDS = { Object.class }; /**