Details
-
Bug
-
Resolution: Fixed
-
P3
-
6
-
None
-
b76
-
b84
-
generic
-
generic
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.
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.
Attachments
Issue Links
- relates to
-
JDK-4741757 LTP: XMLEncoder ignores persistence delegates when used with java web start
- Resolved
-
JDK-7080613 java.beans.DefaultPersistenceDelegate.instantiate(..) doesn't throw NPE
- Closed
-
JDK-6410256 LTP: Possible backward incompatibility in DefaultPersistenceDelegate
- Closed