DATACMNS-132 - Guard against untyped Maps and Collections in AbstractPersistentProperty.isEntity().

Just mentioned method threw a NullPointerException when the property was backed by an untyped Map or Collection as TypeInformation.getActualType() returns null in this case. Changed that to correctly return false.
This commit is contained in:
Oliver Gierke
2012-04-11 07:58:03 +02:00
parent 75c67f0b57
commit 109e7f903e
2 changed files with 29 additions and 1 deletions

View File

@@ -177,7 +177,8 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
protected boolean isEntity() {
boolean isComplexType = !simpleTypeHolder.isSimpleType(information.getActualType().getType());
TypeInformation<?> actualType = information.getActualType();
boolean isComplexType = actualType == null ? false : !simpleTypeHolder.isSimpleType(actualType.getType());
return isComplexType && !isTransient() && !isCollectionLike() && !isMap();
}

View File

@@ -5,6 +5,8 @@ import static org.junit.Assert.*;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Map;
import java.util.TreeSet;
import org.junit.Before;
@@ -54,14 +56,39 @@ public class AbstractPersistentPropertyUnitTests {
assertThat(property.getPersistentEntityType().iterator().hasNext(), is(false));
}
/**
* @see DATACMNS-132
*/
@Test
public void isEntityWorksForUntypedMaps() throws Exception {
Field field = ReflectionUtils.findField(TestClassComplex.class, "map");
SamplePersistentProperty property = new SamplePersistentProperty(field, null, entity, typeHolder);
assertThat(property.isEntity(), is(false));
}
/**
* @see DATACMNS-132
*/
@Test
public void isEntityWorksForUntypedCollection() throws Exception {
Field field = ReflectionUtils.findField(TestClassComplex.class, "collection");
SamplePersistentProperty property = new SamplePersistentProperty(field, null, entity, typeHolder);
assertThat(property.isEntity(), is(false));
}
@SuppressWarnings("serial")
class TestClassSet extends TreeSet<Object> {
}
@SuppressWarnings("rawtypes")
class TestClassComplex {
String id;
TestClassSet testClassSet;
Map map;
Collection collection;
}
class SamplePersistentProperty extends AbstractPersistentProperty<SamplePersistentProperty> {