diff --git a/src/main/java/org/springframework/data/util/TypeDiscoverer.java b/src/main/java/org/springframework/data/util/TypeDiscoverer.java index 1d20a55f4..b20f8382e 100644 --- a/src/main/java/org/springframework/data/util/TypeDiscoverer.java +++ b/src/main/java/org/springframework/data/util/TypeDiscoverer.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2013 the original author or authors. + * Copyright 2011-2014 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. @@ -308,7 +308,7 @@ class TypeDiscoverer implements TypeInformation { public TypeInformation getMapValueType() { if (isMap()) { - return getTypeArgument(getType(), Map.class, 1); + return getTypeArgument(Map.class, 1); } List> arguments = getTypeArguments(); @@ -348,11 +348,11 @@ class TypeDiscoverer implements TypeInformation { } if (isMap()) { - return getTypeArgument(rawType, Map.class, 0); + return getTypeArgument(Map.class, 0); } if (Iterable.class.isAssignableFrom(rawType)) { - return getTypeArgument(rawType, Iterable.class, 0); + return getTypeArgument(Iterable.class, 0); } List> arguments = getTypeArguments(); @@ -448,9 +448,16 @@ class TypeDiscoverer implements TypeInformation { return target.getSuperTypeInformation(getType()).equals(this); } - private TypeInformation getTypeArgument(Class type, Class bound, int index) { - Class[] arguments = GenericTypeResolver.resolveTypeArguments(type, bound); - return arguments == null ? null : createInfo(arguments[index]); + private TypeInformation getTypeArgument(Class bound, int index) { + + Class[] arguments = GenericTypeResolver.resolveTypeArguments(getType(), bound); + + if (arguments == null) { + return getSuperTypeInformation(bound) instanceof ParameterizedTypeInformation ? ClassTypeInformation.OBJECT + : null; + } + + return createInfo(arguments[index]); } /* diff --git a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java index f8ebca1de..508754b50 100644 --- a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java +++ b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2013 the original author or authors. + * Copyright 2011-2014 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. @@ -294,6 +294,16 @@ public class ClassTypeInformationUnitTests { from(null); } + /** + * @see DATACMNS-422 + */ + @Test + public void returnsNullForRawTypesOnly() { + + assertThat(from(MyRawIterable.class).getComponentType(), is(nullValue())); + assertThat(from(MyIterable.class).getComponentType(), is(notNullValue())); + } + static class StringMapContainer extends MapContainer { } @@ -418,4 +428,9 @@ public class ClassTypeInformationUnitTests { interface Identifiable { Long getId(); } + + @SuppressWarnings("rawtypes") + interface MyRawIterable extends Iterable {} + + interface MyIterable extends Iterable {} }