diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java index 18ad2687d..dccb18f3e 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java @@ -148,6 +148,10 @@ public abstract class AbstractPersistentProperty
*/ public Method getGetter() { + if (propertyDescriptor == null) { + return null; + } + Method getter = propertyDescriptor.getReadMethod(); if (getter == null) { @@ -163,6 +167,10 @@ public abstract class AbstractPersistentProperty
*/
public Method getSetter() {
+ if (propertyDescriptor == null) {
+ return null;
+ }
+
Method setter = propertyDescriptor.getWriteMethod();
if (setter == null) {
diff --git a/spring-data-commons-core/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java b/spring-data-commons-core/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
index c21c5e04e..317f789ae 100644
--- a/spring-data-commons-core/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
+++ b/spring-data-commons-core/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
@@ -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