Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-677

Cache annotation absence in AnnotationBasedPersistentProperty when there is no field for property

    XMLWordPrintable

    Details

    • Sprint:
      57 - Fowler Aftermath

      Description

      Currently when there is no annotation on getters/setters and there is no field at all AnnotationBasedPersistentProperty.findAnnotation(…) does not cache annotation absence. This can be easily improved:

      Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      --- a/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java
      +++ b/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java
      @@ -228,7 +228,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
                              }
                      }
      
      -               return field == null ? null : cacheAndReturn(annotationType, AnnotationUtils.getAnnotation(field, annotationType));
      +               return cacheAndReturn(annotationType, field == null ? null : AnnotationUtils.getAnnotation(field, annotationType));
              }
      
              /*
      

      Above works for me and gives some minor performance boost (for those cases when field is absent).

      While doing it it may worth fixing that JavaDoc which lies about order of annotation searching . Looking at implementation It seems that getters/setters are actually searched first.

        Attachments

          Activity

            People

            Assignee:
            olivergierke Oliver Drotbohm
            Reporter:
            tawek Tomasz Wysocki
            Last updater:
            Oliver Drotbohm
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: