Skip to content

Commit ec81344

Browse files
committed
DATACMNS-695 - Fixed potential NullPointerException in AbstractMappingContext.getPersistentPropertyPath(…).
When traversing nested property paths, AbstractMappingContext.getPersistentPropertyPath(…) previously used the raw actual property type. If the property path contains a reference to a generically typed property, this causes the deeper paths not being resolved correctly. We now explicitly use the TypeInformation of the property to retain generics information while traversing the path.
1 parent 638822e commit ec81344

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private PersistentPropertyPath<P> getPersistentPropertyPath(Iterable<String> par
239239
result.add(persistentProperty);
240240

241241
if (iterator.hasNext()) {
242-
current = getPersistentEntity(persistentProperty.getActualType());
242+
current = getPersistentEntity(persistentProperty.getTypeInformation().getActualType());
243243
}
244244
}
245245

src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.List;
2626
import java.util.TreeMap;
2727

28+
import org.hamcrest.Matchers;
2829
import org.junit.Before;
2930
import org.junit.Test;
3031
import org.mockito.Mockito;
@@ -245,6 +246,15 @@ public void doesNotAddMapImplementationClassesAsPersistentEntity() {
245246
assertHasEntityFor(TreeMap.class, context, false);
246247
}
247248

249+
/**
250+
* @see DATACMNS-695
251+
*/
252+
@Test
253+
public void persistentPropertyPathTraversesGenericTypesCorrectly() {
254+
assertThat(context.getPersistentPropertyPath("field.wrapped.field", Outer.class),
255+
is(Matchers.<SamplePersistentProperty> iterableWithSize(3)));
256+
}
257+
248258
private static void assertHasEntityFor(Class<?> type, SampleMappingContext context, boolean expected) {
249259

250260
boolean found = false;
@@ -283,4 +293,17 @@ static class Base {
283293
static class Extension extends Base {
284294
@Id String foo;
285295
}
296+
297+
static class Outer {
298+
299+
Wrapper<Inner> field;
300+
}
301+
302+
static class Wrapper<T> {
303+
T wrapped;
304+
}
305+
306+
static class Inner {
307+
String field;
308+
}
286309
}

0 commit comments

Comments
 (0)