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

PropertyDescriptor ignores default methods from interfaces implemented by superclasses

    XMLWordPrintable

Details

    Description

      FULL PRODUCT VERSION :
      9-ea
      8

      A DESCRIPTION OF THE PROBLEM :
      Default methods on interfaces that are implemented by a super class are ignored by PropertyDescriptor/Introspector. As default methods are part of Java 8+, they should be usable in Beans as well.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create an interface with a default method that looks like a getter (for example: boolean isFoo())
      Implement that interface.
      Extend the implementing class.
      Try to create a PropertyDescriptor with that method's name as the readMethodName

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Access to the method works directly via reflection as well as via PropertyDescriptor
      ACTUAL -
      Instantiating a PropertyDescriptor fails with an IntrospectionException

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.beans.IntrospectionException: Method not found: isFoo
      at java.desktop/java.beans.PropertyDescriptor.<init>(PropertyDescriptor.java:110)
      at Baz.main(Baz.java:7)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.beans.PropertyDescriptor;

      public class Baz extends Bar /*implements Foo*/{
      public static void main(String[] args) throws Exception {
      System.out.println(Baz.class.getMethod("isFoo").invoke(new Baz())); // works

      PropertyDescriptor pd = new PropertyDescriptor("foo", Baz.class, "isFoo", null); //fails
      System.out.println(pd.getReadMethod().invoke(new Baz()));
      }
      }

      class Bar implements Foo{}

      interface Foo{
      public default boolean isFoo(){
      return true;
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Use simple reflection instead of PropertyDescriptor / create PropertyDescriptor for directly implementing parent class

      Attachments

        Issue Links

          Activity

            People

              serb Sergey Bylokhov
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: