Skip to content

Commit 2b14d1e

Browse files
mp911deodrotbohm
authored andcommitted
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.
1 parent ac51b16 commit 2b14d1e

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2014 the original author or authors.
2+
* Copyright 2011-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
3232
* class we will have to resolve generic parameters against.
3333
*
3434
* @author Oliver Gierke
35+
* @author Mark Paluch
3536
*/
3637
class ParameterizedTypeInformation<T> extends ParentTypeAwareTypeInformation<T> {
3738

@@ -85,7 +86,7 @@ protected TypeInformation<?> doGetMapValueType() {
8586
}
8687
}
8788

88-
return super.getMapValueType();
89+
return super.doGetMapValueType();
8990
}
9091

9192
/*

src/test/java/org/springframework/data/util/ParameterizedTypeUnitTests.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2015 the original author or authors.
2+
* Copyright 2011-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@
3939
* Unit tests for {@link ParameterizedTypeInformation}.
4040
*
4141
* @author Oliver Gierke
42+
* @author Mark Paluch
4243
*/
4344
@RunWith(MockitoJUnitRunner.class)
4445
public class ParameterizedTypeUnitTests {
@@ -137,6 +138,19 @@ public void usesLocalGenericInformationOfFields() {
137138
assertThat(valueType.getProperty("value").getType(), is(typeCompatibleWith(Education.class)));
138139
}
139140

141+
/**
142+
* @see DATACMNS-899
143+
*/
144+
@Test
145+
public void returnsNullMapValueTypeForNonMapProperties(){
146+
147+
TypeInformation<?> valueType = ClassTypeInformation.from(Bar.class).getProperty("param");
148+
TypeInformation<?> mapValueType = valueType.getMapValueType();
149+
150+
assertThat(valueType, instanceOf(ParameterizedTypeInformation.class));
151+
assertThat(mapValueType, is(nullValue()));
152+
}
153+
140154
@SuppressWarnings("serial")
141155
class Localized<S> extends HashMap<Locale, S> {
142156
S value;
@@ -152,6 +166,10 @@ class Foo {
152166
Localized2<String> param2;
153167
}
154168

169+
class Bar {
170+
List<String> param;
171+
}
172+
155173
class Parameterized<T> {
156174
T property;
157175
}

0 commit comments

Comments
 (0)