diff --git a/spring-core/src/main/java/org/springframework/core/ResolvableType.java b/spring-core/src/main/java/org/springframework/core/ResolvableType.java index 57160e856b..c89d7611d0 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableType.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableType.java @@ -146,7 +146,7 @@ public final class ResolvableType implements Serializable { * the {@link #NONE} constant, this method will never return {@code null}. */ public Type getType() { - return this.type; + return SerializableTypeWrapper.unwrap(this.type); } /** @@ -1190,7 +1190,8 @@ public final class ResolvableType implements Serializable { @Override public ResolvableType resolveVariable(TypeVariable variable) { for (int i = 0; i < this.typeVariables.length; i++) { - if (this.typeVariables[i].equals(variable)) { + if (SerializableTypeWrapper.unwrap(this.typeVariables[i]).equals( + SerializableTypeWrapper.unwrap(variable))) { return this.generics[i]; } } diff --git a/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java b/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java index 6551228f66..7250ada715 100644 --- a/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java +++ b/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java @@ -128,6 +128,20 @@ abstract class SerializableTypeWrapper { return result; } + /** + * Unwrap the given type, effectively returning the original non-serializable type. + * @param type the type to unwrap + * @return the original non-serializable type + */ + @SuppressWarnings("unchecked") + public static T unwrap(T type) { + Type unwrapped = type; + while (unwrapped instanceof SerializableTypeProxy) { + unwrapped = ((SerializableTypeProxy) type).getTypeProvider().getType(); + } + return (T) unwrapped; + } + /** * Return a {@link Serializable} {@link Type} backed by a {@link TypeProvider} . */ @@ -215,8 +229,8 @@ abstract class SerializableTypeWrapper { if (EQUALS_METHOD.equals(method)) { Object other = args[0]; // Unwrap proxies for speed - while (other instanceof SerializableTypeProxy) { - other = ((SerializableTypeProxy) other).getTypeProvider().getType(); + if (other instanceof Type) { + other = unwrap((Type) other); } return this.provider.getType().equals(other); }