DATACMNS-899 - Fix recursion in ParameterizedTypeInformation.getMapValueType().
Previously, calls to ParameterizedTypeInformation.getMapValueType() caused an infinite recursion when invoked on a type information that was not a map type. This lead to a StackOverflowError. We now call the super method doGetMapValueType() instead of calling the entry super method getMapValueType() and return by that null in case the map value type is not resolvable. Original pull request: #176.
This commit is contained in:
committed by
Oliver Gierke
parent
ac51b1671d
commit
2b14d1ea54
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2014 the original author or authors.
|
||||
* Copyright 2011-2016 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.
|
||||
@@ -32,6 +32,7 @@ import org.springframework.util.StringUtils;
|
||||
* class we will have to resolve generic parameters against.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T> {
|
||||
|
||||
@@ -85,7 +86,7 @@ class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T>
|
||||
}
|
||||
}
|
||||
|
||||
return super.getMapValueType();
|
||||
return super.doGetMapValueType();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
* Copyright 2011-2016 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.
|
||||
@@ -39,6 +39,7 @@ import org.mockito.runners.MockitoJUnitRunner;
|
||||
* Unit tests for {@link ParameterizedTypeInformation}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ParameterizedTypeUnitTests {
|
||||
@@ -137,6 +138,19 @@ public class ParameterizedTypeUnitTests {
|
||||
assertThat(valueType.getProperty("value").getType(), is(typeCompatibleWith(Education.class)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-899
|
||||
*/
|
||||
@Test
|
||||
public void returnsNullMapValueTypeForNonMapProperties(){
|
||||
|
||||
TypeInformation<?> valueType = ClassTypeInformation.from(Bar.class).getProperty("param");
|
||||
TypeInformation<?> mapValueType = valueType.getMapValueType();
|
||||
|
||||
assertThat(valueType, instanceOf(ParameterizedTypeInformation.class));
|
||||
assertThat(mapValueType, is(nullValue()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class Localized<S> extends HashMap<Locale, S> {
|
||||
S value;
|
||||
@@ -152,6 +166,10 @@ public class ParameterizedTypeUnitTests {
|
||||
Localized2<String> param2;
|
||||
}
|
||||
|
||||
class Bar {
|
||||
List<String> param;
|
||||
}
|
||||
|
||||
class Parameterized<T> {
|
||||
T property;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user