JDK-6180799 : Java Bean with zero properties will cause a NullPointerException when getBeanInf
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.4.2_06
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2004-10-18
  • Updated: 2010-04-02
  • Resolved: 2004-11-03
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
1.4.2_06Resolved
Related Reports
Duplicate :  
Description
In JDK 1.4.2_06, a Java Bean with zero properties will cause a NullPointerException when getBeanInfo() is called.

  From my inspection of the source code of java/bean/Introspection.java, I believe this is caused because the pdStore Map is not instantiated until addPropertyDescriptor(PropertyDescriptor) is called.  If a bean has no properties, this is never called.  Then when processPropertyDescriptors() is called, the null pdStore results in immediate return before properties can be assigned to a new HashMap.  In getTargetPropertyInfo(), the call to properties.size()  on line 591 then results in a NPE.

Below is a simple test case and instructions on its execution.

Instructions to Compile and Execute:

javac -g Bisc.java beans/nb.java
java Bisc beans.nb


Results of Execution with JDK 1.4.2_05 (Correct Behavior)

bash-2.05$ java -version
java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)
bash-2.05$ java Bisc beans.nb
Class beans.nb
 
Methods via Bean
bash-2.05$



Results of Execution with JDK 1.4.2_06 (Incorrect Behavior)

bash-2.05$ java -version
java version "1.4.2_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b02)
Java HotSpot(TM) Client VM (build 1.4.2_06-b02, mixed mode)
bash-2.05$ java Bisc beans.nb
java.lang.NullPointerException
        at java.beans.Introspector.getTargetPropertyInfo(Introspector.java:591)
        at java.beans.Introspector.getBeanInfo(Introspector.java:380)
        at java.beans.Introspector.getBeanInfo(Introspector.java:215)
        at java.beans.Introspector.getBeanInfo(Introspector.java:201)
        at Bisc.main(Bisc.java:15)
bash-2.05$


/////////////////////////
/// File: beans/nb.java
/////////////////////////

package beans;

public class nb
{
}
/// End File: beans/nb.java

/////////////////////////
/// File: Bisc.java
/////////////////////////

import java.beans.*;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Bisc
{
    public static void main(String[] args)
    {
        if (args.length != 1)
            System.err.println("Usage: java Bisc <JavaBeanClassName>");

        try
        {
            Class cl = Class.forName(args[0]);
            BeanInfo bi = Introspector.getBeanInfo(cl, cl.getSuperclass());

            PropertyDescriptor[] pds = bi.getPropertyDescriptors();

            System.out.println("Class " + args[0]);

            System.out.println("\nMethods via Bean");
            for (int i = 0; i < pds.length; i++)
            {
                PropertyDescriptor pd = pds[i];
                System.out.println("Prop " + pd.getName());
                Method rm = pd.getReadMethod();
                Method wm = pd.getWriteMethod();

                if (rm != null)
                {
                    System.out.print("Read method: ");
                    methodInfo(rm);
                }
                else
                    System.out.println("Read method is null");

                if (wm != null)
                {
                    System.out.print("Write method: ");
                    methodInfo(wm);
                }
                else
                    System.out.println("Write method is null");
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    static void methodInfo(Method m)
    {
        System.out.println(m.getName());
        System.out.println("    modifiers: " +
            Modifier.toString(m.getModifiers()));
        System.out.println("    declaring class: " + m.getDeclaringClass());
    }
}

/// End File: Bisc.java
###@###.### 10/18/04 21:17 GMT

Comments
EVALUATION Need to investigate this issue. ###@###.### 10/20/04 09:42 GMT I've tried to reproduce this bug with mustang and 1.4.2_06 build 03 (I don't have other builds of 1.4.2_06) but unsuccessfully. This is probably some duplicate of an already fixed bug. I'll try to find the appropriate BugID, but ###@###.###, could you please test the provided testcase on build 03 or later? The exception is thrown on build 02. ###@###.### 10/29/04 12:20 GMT This is probably a duplicate of 4948761. ###@###.### 10/29/04 12:42 GMT It has been confirmed by Oracle that bug is no longer reproducible. Closing as a duplicate of 4948761. ###@###.### 11/3/04 11:46 GMT
20-10-2004