DATACMNS-677 - AnnotationBasedPersistentProperty now caches absence of annotations on accessor-only properties.

AnnotationBasedPersistentProperty now also caches the absence of properties that are expressed through accessors only. Previously the absence of a field caused us to skip the registration of the absence in the cache.
This commit is contained in:
Oliver Gierke
2015-04-07 08:39:59 +02:00
parent 1d2ad3f2b4
commit b0211911b5
2 changed files with 28 additions and 3 deletions

View File

@@ -203,6 +203,23 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
getProperty(TypeWithCustomAnnotationsOnBothFieldAndAccessor.class, "field");
}
/**
* @see DATACMNS-677
*/
@Test
@SuppressWarnings("unchecked")
public void cachesNonPresenceOfAnnotationOnField() {
SamplePersistentProperty property = getProperty(Sample.class, "getterWithoutField");
assertThat(property.findAnnotation(MyAnnotation.class), is(nullValue()));
Map<Class<?>, ?> field = (Map<Class<?>, ?>) ReflectionTestUtils.getField(property, "annotationCache");
assertThat(field.containsKey(MyAnnotation.class), is(true));
assertThat(field.get(MyAnnotation.class), is(nullValue()));
}
@SuppressWarnings("unchecked")
private Map<Class<? extends Annotation>, Annotation> getAnnotationCache(SamplePersistentProperty property) {
return (Map<Class<? extends Annotation>, Annotation>) ReflectionTestUtils.getField(property, "annotationCache");
@@ -250,6 +267,13 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
public void setDoubleMapping(String doubleMapping) {
this.doubleMapping = doubleMapping;
}
@AccessType(Type.PROPERTY)
public Object getGetterWithoutField() {
return null;
}
public void setGetterWithoutField(Object object) {}
}
static class InvalidSample {