diff --git a/org.springframework.core/src/main/java/org/springframework/core/GenericTypeResolver.java b/org.springframework.core/src/main/java/org/springframework/core/GenericTypeResolver.java index 211b7d41984..95e870f3062 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/GenericTypeResolver.java +++ b/org.springframework.core/src/main/java/org/springframework/core/GenericTypeResolver.java @@ -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"); * you may not use this file except in compliance with the License. @@ -41,7 +41,6 @@ import org.springframework.util.Assert; * @author Rob Harrop * @since 2.5.2 * @see GenericCollectionTypeResolver - * @see JdkVersion */ public abstract class GenericTypeResolver { @@ -175,7 +174,7 @@ public abstract class GenericTypeResolver { 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 null; diff --git a/org.springframework.core/src/test/java/org/springframework/core/GenericTypeResolverTests.java b/org.springframework.core/src/test/java/org/springframework/core/GenericTypeResolverTests.java index df595e3f2c0..ae58178dc98 100644 --- a/org.springframework.core/src/test/java/org/springframework/core/GenericTypeResolverTests.java +++ b/org.springframework.core/src/test/java/org/springframework/core/GenericTypeResolverTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -18,9 +18,10 @@ package org.springframework.core; import java.util.Collection; -import static org.junit.Assert.*; import org.junit.Test; +import static org.junit.Assert.*; + /** * @author Juergen Hoeller */ @@ -46,6 +47,12 @@ public class GenericTypeResolverTests { assertEquals(Collection.class, GenericTypeResolver.resolveTypeArgument(MyCollectionSuperclassType.class, MySuperclassType.class)); } + @Test + public void testNullIfNotResolvable() { + GenericClass obj = new GenericClass(); + assertNull(GenericTypeResolver.resolveTypeArgument(obj.getClass(), GenericClass.class)); + } + public interface MyInterfaceType { } @@ -66,4 +73,7 @@ public class GenericTypeResolverTests { public class MyCollectionSuperclassType extends MySuperclassType> { } + static class GenericClass { + } + }