JDK-4867168 : BeanInfo gets lost when it contains a PropertyDescriptor without a Readmethod
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2003-05-21
  • Updated: 2003-09-05
  • Resolved: 2003-09-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Related Reports
Relates :  
Description

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) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b19
14-06-2004

EVALUATION The submitter has indeed found a bug. Which is a regression that was introduced as a result of the fix to 4750368. While I don't agree with write only properties, we shouldn't break existing applications. Unfortunately, this issue has been caught way too late in the development process so it will not be fixed for 1.4.2 FCS. The reflective Introspector will not create write only property descriptors so the only way to trip over this bug is to implement a specific BeanInfo that doens't have a read method. This bug is quite rare and is not a show stopper for 1.4.2 but will be commited to 1.5 ###@###.### 2003-05-22 Very tricky. The suggested fix in the Introspector is one part of the solution but another bug has been introduced as a result of the fix to 4809008. The writeMethod in the PropertyDescriptor cannot be found from a String if the readMethod doesn't exist. The type of the writeMethod is determined by the readMethod. The findPropertyType returns null for readMethod = null and writeMethod = null. The only way to resolve this in getWriteMethod is to detect the case in which type == null and call Introspector.findMethod(cls, writeMethodName, 1, null); ###@###.### 2003-08-14
14-08-2003