GenericTypeResolver's resolveTypeArguments needs to return null for raw types (for backwards compatibility with 3.2)

Issue: SPR-11052
This commit is contained in:
Juergen Hoeller
2013-10-31 15:28:20 +01:00
parent 84bc474016
commit 9f3b8a2430
4 changed files with 53 additions and 56 deletions

View File

@@ -240,12 +240,12 @@ public abstract class GenericTypeResolver {
* @return the resolved type of each argument, with the array size matching the
* number of actual type arguments, or {@code null} if not resolvable
*/
public static Class[] resolveTypeArguments(Class<?> clazz, Class<?> genericIfc) {
public static Class<?>[] resolveTypeArguments(Class<?> clazz, Class<?> genericIfc) {
ResolvableType type = ResolvableType.forClass(clazz).as(genericIfc);
if (!type.hasGenerics()) {
if (!type.hasGenerics() || type.hasUnresolvableGenerics()) {
return null;
}
return type.resolveGenerics(Object.class);
return type.resolveGenerics();
}
/**

View File

@@ -567,7 +567,7 @@ public final class ResolvableType implements Serializable {
this.resolved = resolveClass();
this.isResolved = true;
}
return (this.resolved == null ? fallback : this.resolved);
return (this.resolved != null ? this.resolved : fallback);
}
private Class<?> resolveClass() {
@@ -576,7 +576,7 @@ public final class ResolvableType implements Serializable {
}
if (this.type instanceof GenericArrayType) {
Class<?> resolvedComponent = getComponentType().resolve();
return (resolvedComponent == null ? null : Array.newInstance(resolvedComponent, 0).getClass());
return (resolvedComponent != null ? Array.newInstance(resolvedComponent, 0).getClass() : null);
}
return resolveType().resolve();
}

View File

@@ -138,10 +138,17 @@ public class GenericTypeResolverTests {
}
@Test
public void getGenericsCannotBeResovled() throws Exception {
public void getGenericsCannotBeResolved() throws Exception {
// SPR-11030
Class[] resolved = GenericTypeResolver.resolveTypeArguments(List.class, Iterable.class);
assertThat(resolved, equalTo(new Class[] { Object.class }));
Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(List.class, Iterable.class);
assertNull(resolved);
}
@Test
public void getRawMapTypeCannotBeResolved() throws Exception {
// SPR-11052
Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(Map.class, Map.class);
assertNull(resolved);
}
@Test
@@ -300,11 +307,9 @@ public class GenericTypeResolverTests {
static abstract class WithArrayBase<T> {
public abstract T[] array(T... args);
}
static abstract class WithArray<T> extends WithArrayBase<T> {
}
}