Unwrap TypeVariables before calling .equals()

Update ResolvableType to unwrap Serialization wrapped TypeVariables
before calling the equals method.

This protects against the recent change in OpenJDK 8 (build 124)
which changed the TypeVariableImpl equals method such that it only
matches against other TypeVariableImpl instances.

Issue: SPR-11342
This commit is contained in:
Phillip Webb 2014-01-21 16:04:13 -08:00
parent d03fb8954b
commit 59604b1cd5
2 changed files with 19 additions and 4 deletions

View File

@ -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];
}
}

View File

@ -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 extends Type> 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);
}