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 1f463565d250..33f7d7d5f3e3 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableType.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableType.java @@ -138,7 +138,7 @@ private boolean isAssignableFrom(ResolvableType type, boolean checkingGeneric) { Assert.notNull(type, "Type must not be null"); // If we cannot resolve types, we are not assignable - if (resolve() == null || type.resolve() == null) { + if (this == NONE || type == NONE) { return false; } @@ -164,15 +164,16 @@ private boolean isAssignableFrom(ResolvableType type, boolean checkingGeneric) { } // Main assignability check - boolean rtn = resolve().isAssignableFrom(type.resolve()); + boolean rtn = resolve(Object.class).isAssignableFrom(type.resolve(Object.class)); // We need an exact type match for generics // List is not assignable from List - rtn &= (!checkingGeneric || resolve().equals(type.resolve())); + rtn &= (!checkingGeneric || resolve(Object.class).equals(type.resolve(Object.class))); // Recursively check each generic for (int i = 0; i < getGenerics().length; i++) { - rtn &= getGeneric(i).isAssignableFrom(type.as(resolve()).getGeneric(i), true); + rtn &= getGeneric(i).isAssignableFrom( + type.as(resolve(Object.class)).getGeneric(i), true); } return rtn; diff --git a/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java b/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java index b4a91079ec00..39eef888a7c6 100644 --- a/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java +++ b/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java @@ -52,8 +52,6 @@ import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; -// FIXME nested - /** * Tests for {@link ResolvableType}. * @@ -822,8 +820,8 @@ public void isAssignableFromCannotBeResolved() throws Exception { ResolvableType objectType = ResolvableType.forClass(Object.class); ResolvableType unresolvableVariable = ResolvableType.forField(AssignmentBase.class.getField("o")); assertThat(unresolvableVariable.resolve(), nullValue()); - assertAssignable(objectType, unresolvableVariable).equalTo(false); - assertAssignable(unresolvableVariable, objectType).equalTo(false); + assertAssignable(objectType, unresolvableVariable).equalTo(true); + assertAssignable(unresolvableVariable, objectType).equalTo(true); } @Test @@ -936,6 +934,7 @@ public void isAssignableFromForWildcards() throws Exception { ResolvableType object = ResolvableType.forClass(Object.class); ResolvableType charSequence = ResolvableType.forClass(CharSequence.class); ResolvableType string = ResolvableType.forClass(String.class); + ResolvableType extendsAnon = ResolvableType.forField(AssignmentBase.class.getField("listAnon"), Assignment.class).getGeneric(); ResolvableType extendsObject = ResolvableType.forField(AssignmentBase.class.getField("listxo"), Assignment.class).getGeneric(); ResolvableType extendsCharSequence = ResolvableType.forField(AssignmentBase.class.getField("listxc"), Assignment.class).getGeneric(); ResolvableType extendsString = ResolvableType.forField(AssignmentBase.class.getField("listxs"), Assignment.class).getGeneric(); @@ -972,6 +971,8 @@ public void isAssignableFromForWildcards() throws Exception { equalTo(false, true, true); assertAssignable(charSequence, extendsObject, extendsCharSequence, extendsString). equalTo(false, false, false); + assertAssignable(extendsAnon, object, charSequence, string). + equalTo(true, true, true); // T <= ? super T assertAssignable(superCharSequence, object, charSequence, string). @@ -1144,6 +1145,8 @@ static class AssignmentBase { public List lists; + public List listAnon; + public List listxo; public List listxc;