Browse Source

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.
pull/123/merge
Oliver Gierke 11 years ago
parent
commit
5b60d487e1
  1. 2
      src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java
  2. 23
      src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java

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

@ -239,7 +239,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<? @@ -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());
}
}

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

@ -25,6 +25,7 @@ import java.util.Iterator; @@ -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 { @@ -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 { @@ -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;
}
}

Loading…
Cancel
Save