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.
This commit is contained in:
Oliver Gierke
2015-05-13 18:33:58 +02:00
parent abe0ac13b5
commit a4118e4374
2 changed files with 24 additions and 1 deletions

View File

@@ -239,7 +239,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
result.add(persistentProperty);
if (iterator.hasNext()) {
current = getPersistentEntity(persistentProperty.getActualType());
current = getPersistentEntity(persistentProperty.getTypeInformation().getActualType());
}
}

View File

@@ -25,6 +25,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.TreeMap;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -245,6 +246,15 @@ public class AbstractMappingContextUnitTests {
assertHasEntityFor(TreeMap.class, context, false);
}
/**
* @see DATACMNS-695
*/
@Test
public void persistentPropertyPathTraversesGenericTypesCorrectly() {
assertThat(context.getPersistentPropertyPath("field.wrapped.field", Outer.class),
is(Matchers.<SamplePersistentProperty> iterableWithSize(3)));
}
private static void assertHasEntityFor(Class<?> type, SampleMappingContext context, boolean expected) {
boolean found = false;
@@ -283,4 +293,17 @@ public class AbstractMappingContextUnitTests {
static class Extension extends Base {
@Id String foo;
}
static class Outer {
Wrapper<Inner> field;
}
static class Wrapper<T> {
T wrapped;
}
static class Inner {
String field;
}
}