fixed GenericTypeResolver to consistently return null if not resolvable (SPR-8698)
This commit is contained in:
parent
3bd9a3e3e0
commit
36616a0c2c
|
|
@ -25,7 +25,6 @@ import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.lang.reflect.TypeVariable;
|
import java.lang.reflect.TypeVariable;
|
||||||
import java.lang.reflect.WildcardType;
|
import java.lang.reflect.WildcardType;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -205,7 +204,7 @@ public abstract class GenericTypeResolver {
|
||||||
return doResolveTypeArguments(ownerClass, (Class) rawType, genericIfc);
|
return doResolveTypeArguments(ownerClass, (Class) rawType, genericIfc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (genericIfc.isAssignableFrom((Class) ifc)) {
|
else if (ifc != null && genericIfc.isAssignableFrom((Class) ifc)) {
|
||||||
return doResolveTypeArguments(ownerClass, (Class) ifc, genericIfc);
|
return doResolveTypeArguments(ownerClass, (Class) ifc, genericIfc);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2010 the original author or authors.
|
* Copyright 2002-2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -18,10 +18,12 @@ package org.springframework.core;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
|
|
@ -55,6 +57,12 @@ public class GenericTypeResolverTests {
|
||||||
assertEquals(null, GenericTypeResolver.resolveReturnTypeArgument(ReflectionUtils.findMethod(MyTypeWithMethods.class, "object"), MyInterfaceType.class));
|
assertEquals(null, GenericTypeResolver.resolveReturnTypeArgument(ReflectionUtils.findMethod(MyTypeWithMethods.class, "object"), MyInterfaceType.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNullIfNotResolvable() {
|
||||||
|
GenericClass<String> obj = new GenericClass<String>();
|
||||||
|
assertNull(GenericTypeResolver.resolveTypeArgument(obj.getClass(), GenericClass.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface MyInterfaceType<T> {
|
public interface MyInterfaceType<T> {
|
||||||
}
|
}
|
||||||
|
|
@ -83,4 +91,7 @@ public class GenericTypeResolverTests {
|
||||||
public MyInterfaceType raw() { return null; }
|
public MyInterfaceType raw() { return null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class GenericClass<T> {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue