Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8027906

BeanInfo.getPropertyDescriptors() can return property with wrong type

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • None
    • 7u25
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.7.0_25"
      Java(TM) SE Runtime Environment (build 1.7.0_25-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      If a JavaBean class has properties that are inherited from a generic interface, java.beans.BeanInfo can find a PropertyDescriptor corresponding to synthetic bridge methods and not the actual typed methods.

      This problem is similar to bug JDK-6788525

      Unfortunately it can still occur in JRE7 but is not reproducable. It depends on the order of the methods returned by "Method[] java.lang.Class.getMethods()" if the result is correct or not.

      The javadoc of this method says "... The elements in the array returned are not sorted and are not in any particular order..." but the Introspector uses the order to create the property descriptors. Therefore it can happen that a wrong property descriptor is returned.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      unfortunately this bug is non-deterministic. most times the result is correct but unfortunately not always!

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      class of type class java.lang.Class
      foo of type class java.lang.String

      ACTUAL -
      class of type class java.lang.Class
      foo of type class java.lang.Object


      REPRODUCIBILITY :
      This bug can be reproduced rarely.

      ---------- BEGIN SOURCE ----------
      import java.beans.BeanInfo;
      import java.beans.IntrospectionException;
      import java.beans.Introspector;
      import java.beans.PropertyDescriptor;

      interface Super<T> {
      public T getFoo();

      public void setFoo(T t);
      }

      class Sub implements Super<String> {
      public String getFoo() {
      return null;
      }

      public void setFoo(String t) {
      }
      }

      public class Main {
      public static void main(String[] args) throws IntrospectionException {
      BeanInfo beanInfo = Introspector.getBeanInfo(Sub.class);

      PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();

      for (PropertyDescriptor prop : propertyDescriptors) {
      System.out.printf("%s of type %s
      ", prop.getName(), prop.getPropertyType());
      }
      }
      }

      ---------- END SOURCE ----------

            malenkov Sergey Malenkov (Inactive)
            malenkov Sergey Malenkov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: