DATACMNS-206 - Guard against PropertyDescriptor being null.
Added guards to PropertyDescriptor access to prevent NullPointerExceptions in cases it is not given in the first place. Polished JavaDoc for test case.
This commit is contained in:
@@ -148,6 +148,10 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
|
||||
*/
|
||||
public Method getGetter() {
|
||||
|
||||
if (propertyDescriptor == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Method getter = propertyDescriptor.getReadMethod();
|
||||
|
||||
if (getter == null) {
|
||||
@@ -163,6 +167,10 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
|
||||
*/
|
||||
public Method getSetter() {
|
||||
|
||||
if (propertyDescriptor == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Method setter = propertyDescriptor.getWriteMethod();
|
||||
|
||||
if (setter == null) {
|
||||
|
||||
@@ -125,6 +125,9 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
assertThat(property.isTransient(), is(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-206
|
||||
*/
|
||||
@Test
|
||||
public void findsSimpleGettersAndASetters() {
|
||||
|
||||
@@ -136,6 +139,9 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
assertThat(property.getSetter(), is(notNullValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-206
|
||||
*/
|
||||
@Test
|
||||
public void doesNotUseInvalidGettersAndASetters() {
|
||||
|
||||
@@ -147,6 +153,9 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
assertThat(property.getSetter(), is(nullValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-206
|
||||
*/
|
||||
@Test
|
||||
public void usesCustomGetter() {
|
||||
|
||||
@@ -158,6 +167,9 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
assertThat(property.getSetter(), is(nullValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-206
|
||||
*/
|
||||
@Test
|
||||
public void usesCustomSetter() {
|
||||
|
||||
@@ -169,6 +181,20 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
assertThat(property.getSetter(), is(notNullValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-206
|
||||
*/
|
||||
@Test
|
||||
public void returnsNullGetterAndSetterIfNoPropertyDescriptorGiven() {
|
||||
|
||||
Field field = ReflectionUtils.findField(AccessorTestClass.class, "id");
|
||||
PersistentProperty<SamplePersistentProperty> property = new SamplePersistentProperty(field, null, entity,
|
||||
typeHolder);
|
||||
|
||||
assertThat(property.getGetter(), is(nullValue()));
|
||||
assertThat(property.getSetter(), is(nullValue()));
|
||||
}
|
||||
|
||||
private static PropertyDescriptor getPropertyDescriptor(Class<?> type, String propertyName) {
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user