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

Introspector.getBeanInfo ignore properties of boxed Boolean type

    XMLWordPrintable

Details

    • x86_64
    • windows_10

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Tested in jdk1.8.0_51.
      Won't work in jdk11.04, either.

      A DESCRIPTION OF THE PROBLEM :
      In "Introspector.getTargetPropertyInfo" method, it only support primitive "boolean" type.
                          if (argCount == 0) {
                              if (name.startsWith(GET_PREFIX)) {
                                  // Simple getter
                                  pd = new PropertyDescriptor(this.beanClass, name.substring(3), method, null);
                              } else if (resultType == boolean.class && name.startsWith(IS_PREFIX)) {
                                  // Boolean getter
                                  pd = new PropertyDescriptor(this.beanClass, name.substring(2), method, null);
                              }
                          }


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Define a class with a public method of type "Boolean".

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      print "class" and "isFirst".
      ACTUAL -
      print "class"

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

      class Child {
          public Boolean isFirst() {
              return true;
          }
      }

      public class JdkBug {
          public static void main(String[] args) {
              try {
                  BeanInfo beanInfo = Introspector.getBeanInfo(Child.class);
                  // Only get "class" property
                  for (PropertyDescriptor propertyDescriptor: beanInfo.getPropertyDescriptors()) {
                      System.out.println(propertyDescriptor.getName());
                  }
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


      Attachments

        Activity

          People

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: