Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-1047

Bean introspection is not compatible with Java 8 compiler

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 7.0.0.Final
    • None
    • core engine
    • None
    • NEW
    • NEW

      Consider the following 2 interfaces:

          public interface Base {
              Object getA();
          }
      
          public interface Ext extends Base {
              String getA();
          }
      

      In Java 7 if you print the declared methods of the Ext interface:

      System.out.println( Arrays.toString(Ext.class.getDeclaredMethods()) );

      you obtain only one method:

      [public abstract java.lang.String org.drools.compiler.IntrospectionTest$Ext.getA()]

      This is expected because Class.getDeclaredMethods() "Returns an array containing Method objects reflecting all the declared methods of the class or interface represented by this Class object, including public, protected, default (package) access, and private methods, but excluding inherited methods." https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getDeclaredMethods--

      Nevertheless if I try exactly the same thing in Java 8 I obtain a totally different result:

      [public abstract java.lang.String org.drools.compiler.IntrospectionTest$Ext1.getA(),
      public default java.lang.Object org.drools.compiler.IntrospectionTest$Ext1.getA()]

      Now it is also returning the method declared on the Base interface as it was a default method. This second method is flagged as a bridge method (see here https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getMethod-java.lang.String-java.lang.Class...- )

      This change between Java 7 and 8 breaks getter/setter introspection of beans in some specific case

            mfusco@redhat.com Mario Fusco
            mfusco@redhat.com Mario Fusco
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: