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

java.beans.Introspector misses default interface methods

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • tbd
    • 8u45
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
      Java HotSpot(TM) Client VM (build 25.45-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.3.9600]

      A DESCRIPTION OF THE PROBLEM :
      Bean properties declared as default interface methods, are not available in the list of properties returned by java.beans.Introspector.getBeanInfo(...).getPropertyDescriptors()

      see also here: http://stackoverflow.com/questions/23219006/default-method-in-interface-in-java-8-and-bean-info-introspector

      In Introspector#getPublicDeclaredMethods(), the following piece of code:

      if (!method.getDeclaringClass().equals(clz)) {
          result[i] = null; // ignore methods declared elsewhere
      }

      should look like this:

      if (!method.getDeclaringClass().equals(clz) && !method.getDeclaringClass().isInterface()) {
          result[i] = null; // ignore methods declared elsewhere
      }

      or be removed completely

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the attached test case

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      class, letter
      class, letter
      ACTUAL -
      class
      class, letter

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.beans.*;
      import java.util.*;
      import java.util.stream.*;

      public class Bug
      {

      public static interface Interface {
          default public String getLetter() {
              return "A";
          }
      }

      public static class ClassA implements Interface {
      }

      public static class ClassB implements Interface {
          public String getLetter() {
              return "B";
          }
      }

      public static String formatData(PropertyDescriptor[] pds) {
          return Arrays.asList(pds).stream()
                  .map((pd) -> pd.getName()).collect(Collectors.joining(", "));

      }

      public static void main(String[] args) {
          try {
              System.out.println(
                      formatData(Introspector.getBeanInfo(ClassA.class)
                              .getPropertyDescriptors()));
              System.out.println(
                      formatData(Introspector.getBeanInfo(ClassB.class)
                              .getPropertyDescriptors()));
          } catch (IntrospectionException e) {
              e.printStackTrace();
          }
      }

      }
      ---------- END SOURCE ----------

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

              Created:
              Updated:
              Resolved: