From 2b14d1ea54f6f0ecb29a0e2ce02b808021210058 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 30 Aug 2016 16:45:21 +0200 Subject: [PATCH] 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. --- .../util/ParameterizedTypeInformation.java | 5 +++-- .../data/util/ParameterizedTypeUnitTests.java | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java b/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java index 01a0a2647..778a7cd89 100644 --- a/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java +++ b/src/main/java/org/springframework/data/util/ParameterizedTypeInformation.java @@ -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 extends ParentTypeAwareTypeInformation { @@ -85,7 +86,7 @@ class ParameterizedTypeInformation extends ParentTypeAwareTypeInformation } } - return super.getMapValueType(); + return super.doGetMapValueType(); } /* diff --git a/src/test/java/org/springframework/data/util/ParameterizedTypeUnitTests.java b/src/test/java/org/springframework/data/util/ParameterizedTypeUnitTests.java index 5d3f67106..a75b4d618 100644 --- a/src/test/java/org/springframework/data/util/ParameterizedTypeUnitTests.java +++ b/src/test/java/org/springframework/data/util/ParameterizedTypeUnitTests.java @@ -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 extends HashMap { S value; @@ -152,6 +166,10 @@ public class ParameterizedTypeUnitTests { Localized2 param2; } + class Bar { + List param; + } + class Parameterized { T property; }