JDK-6412286 : DOC: LTP: Unspecified NPE in java.beans.DefaultPersistenceDelegate.instantiate method
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-04-12
  • Updated: 2017-05-16
  • Resolved: 2010-02-16
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.
JDK 7
7 b84Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
The problem is that if to run java.beans.DefaultPersistenceDelegate.instantiate(Object oldInstance, Encoder out) method with parameter "out = null" then unspecified NPE happens is some cases (*since b76*). 

Steps to reproduce:
1)if java bean is located in separate MyBean.java file in the same package, but it is not public
------------------File Bean.java -------------------------------------------
import java.beans.*;

public class Bean{

	public static void main(String args[]){

        	Object oldInstance = new MyBean("Test");
        	String[] constructorPropertyNames = {"arg"};
	        MyPersistenceDelegate dpd = new MyPersistenceDelegate(constructorPropertyNames);

        	Expression exp = dpd.instantiate(oldInstance, null);
                      //Expression exp = dpd.instantiate(oldInstance, new Encoder());

		System.out.println(exp);
	}
}

class MyPersistenceDelegate extends DefaultPersistenceDelegate {

    public MyPersistenceDelegate() {
        super();
    }

    public MyPersistenceDelegate(String[] constructorPropertyNames) {
        super(constructorPropertyNames);
    }

    public Expression instantiate(Object oldInctance, Encoder out) {
        return super.instantiate(oldInctance, out);
    }
}

------------------File MyBean.java -------------------------------------------
class MyBean {
    private String arg; 
    public MyBean() {
        super();
    }
    public MyBean(String arg) {
        this.arg = arg;
    }
    public String getArg() {
        return arg;
    }
    public void setArg(String arg) {
        this.arg = arg;
    }
}
======================================================================================================================================
2) if java bean is located in the same Bean.java file. (See example in CR 6401499)

In case if "out = new Encoder();" (!= null) and MyBean class *is not public* then another problem arise:
If uncomment the commented line in example 1) then you'll see the following output:
--------------
java.lang.IllegalAccessException: Class java.beans.DefaultPersistenceDelegate can not access a member of class bugfixbeans.test.MyBean with modifiers "public"
Continuing ...
MyBean=Class.new(null);
--------------

Which is not expected. 
Expected output is: 
---------------
MyBean=Class.new("Test");
--------------

It seems to be that such behaviour should be either corrected or specified.

See also CR 6401499.

Comments
EVALUATION Javadoc should declare that the out parameter should not be {@code null}, because these classes are designed to be called automatically from the given encoder.
10-12-2009

EVALUATION I think this is a documentation bug. We should describe behavior of DefaultPersistenceDelegate more clearly or fix NPE in other methods too.
13-04-2006