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

BeanInfo gets lost when it contains a PropertyDescriptor without a Readmethod

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 5.0
    • 1.4.2
    • client-libs
    • tiger
    • x86
    • windows_xp



      Name: gm110360 Date: 05/20/2003


      FULL PRODUCT VERSION :
      java version "1.4.2-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
      Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)

      FULL OS VERSION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      I have written a BeanInfo class that returns at getPropertyDescriptors() one PropertyDescriptor among others that has no Read method. (This is a write-only property according to the API specification, thus allowed). But in this case, Introspector.getBeanInfo(Class beanclass) will use a GenericBeanInfo instead of MyBeanInfo.
      Most probably the reason for that is the new code in Introspector.findExplicitBeanInfo (Under the comment "Make sure that the returned BeanInfo matches the class.")
         Method method = pds[j].getReadMethod();
         if (method.getDeclaringClass() ........
      PropertyDescriptor.getReadMethod() may return null! (And the NullPointerException will be "silently ignored")

        To reproduce this problem, the write-only property has to be the first one returned by getPropertyDescriptors(), but also all properties can be write-only.
      And the BeanInfo class has to be in a different package as the class, which is added to the Introspector's BeanInfoSearchPath.

      Compare to Bug 4855594, and also to Bug xxxxxxx (the one that I submitted on 6th march, against jdk1.4.1, concerning ProeprtyDescriptors without either getmethod and setmethod)



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package classes;

      import java.beans.*;

      public class Bug2
      {
          public static void main(String[] args)
          {
              String[] bsp = Introspector.getBeanInfoSearchPath();
              String[] bspNew = new String[bsp.length+1];
              bspNew[0] = "beaninfos";
              for (int i=0; i<bsp.length; i++) {
                  bspNew[i+1] = bsp[i];
              }
              Introspector.setBeanInfoSearchPath(bspNew);

              try
              {
                  BeanInfo bi = Introspector.getBeanInfo(Bug2.class);
                  PropertyDescriptor[] pd = bi.getPropertyDescriptors();
                  for (int i=0; i<pd.length; i++)
                  {
                      String n = pd[i].getName();
                      System.out.println(n);
                  }
              }
              catch (Exception e)
              {
                  e.printStackTrace();
                  System.exit(1);
              }
              System.exit(0);
          }

          private int f=0;
          public void setF(int P_f) { f = P_f; }
          public int getF() { return f; }

          private int g=0;
          public void setG(int P_g) { g = P_g; }
          public int getG() { return g; }
      }

      --------------------------------------------------------------------

      package beaninfos;

      import classes.Bug2;
      import java.beans.*;

      public class Bug2BeanInfo extends SimpleBeanInfo
      {
          public PropertyDescriptor[] getPropertyDescriptors()
          {
              PropertyDescriptor fDes, gDes;
              try
              {
                  fDes = new PropertyDescriptor("f_from_my_BeanInfo",
                                                Bug2.class,
                                                null, //"getF" would work here
                                                "setF");
                  gDes = new PropertyDescriptor("g_from_my_BeanInfo",
                                                Bug2.class,
                                                "getG",
                                                "setG");
                  return new PropertyDescriptor[] {fDes, gDes};
              }
              catch (IntrospectionException e)
              {
                  e.printStackTrace();
                  return null;
              }
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Return a PropertyDescriptor-Array whit the write-only property not at the first position. (But what if the class has only write-only properties?)
      (Review ID: 186072)
      ======================================================================

            mdavidsosunw Mark Davidson (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: