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

AbstractPersistentProperty.getGetter() returns null if the return type of the getter is a generic type

    XMLWordPrintable

    Details

    • Sprint:
      Kay SR1

      Description

      This issue is introduced in revision 766c9078f23d9af9a8d6ebc3b991c07fadee3594(DATACMNS-1139).

      return rawType.isAssignableFrom(getter.getReturnType()) ? getter : null;
      

      Seems this line(in method AbstractPersistentProperty.getGetter()) makes it return null, the rawType is the generic type, but the getter.getReturnType() is Object.

      Add these asserts could reproduce this issue :

      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
      diff --git a/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java b/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
      index 65c8b494..044989d2 100644
      --- a/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
      +++ b/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
      @@ -206,6 +206,17 @@ public class AbstractPersistentPropertyUnitTests {
                      SamplePersistentProperty property = getProperty(FirstConcrete.class, "genericField");
       
                      assertThat(property.getRawType(), is(typeCompatibleWith(String.class)));
      +
      +               // From DATACMNS-1139, the rawType changes from Object.class to String.class
      +               assertEquals(String.class, property.getRawType());
      +               // But the return type is still Object.class
      +               assertEquals(Object.class, property.propertyDescriptor.getReadMethod().getReturnType());
      +
      +               // And finally this false makes the getGetter returns null
      +               assertFalse(property.getRawType().isAssignableFrom(property.propertyDescriptor.getReadMethod().getReturnType()));
      +
      +               assertThat(property.getGetter(), is(notNullValue()));
      +               assertThat(property.getSetter(), is(notNullValue()));
              }
       
              private <T> SamplePersistentProperty getProperty(Class<T> type, String name) {
      @@ -241,7 +252,15 @@ public class AbstractPersistentPropertyUnitTests {
              }
       
              class Generic<T> {
      -               T genericField;
      +               private T genericField;
      +
      +               public T getGenericField() {
      +                       return genericField;
      +               }
      +
      +               public void setGenericField(T genericField) {
      +                       this.genericField = genericField;
      +               }
       
              }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              sutra Sutra Zhou
              Last updater:
              Oliver Drotbohm
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: