Name: rmT116609 Date: 02/12/2004
FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
See attached code.
ERROR reported
java.lang.ClassNotFoundException: [Lde.gaskin.xml.test.EnDecodeBug1$Obj;
Continuing ...
java.lang.RuntimeException: failed to evaluate: <unbound>=Class.forName("[Lde.ga
skin.xml.test.EnDecodeBug1$Obj;");
Continuing ...
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See comments in source code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
As with JDK1.4.X
ACTUAL -
The XMLEndoder produced file is incomplete
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.ClassNotFoundException: [Lde.gaskin.xml.test.EnDecodeBug1$Obj;
Continuing ...
java.lang.RuntimeException: failed to evaluate: <unbound>=Class.forName("[Lde.ga
skin.xml.test.EnDecodeBug1$Obj;");
Continuing ...
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package de.gaskin.xml.test;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
/** Demonstrate XMLEncoder/XMLDecoder BUG with arrays that have a dimension > 1
in JDK1.5 beta1.
Compile with 1.4.X or 1.5.
Run with 1.4 OK.
Run with 1.5 E R R O R.
Usage:
java de.gaskin.xml.test.EnDecodeBug1 [-nowrite] [filename]
Default filename is "bug1.xml"
No switch (-nowrite) writes with XMLEncoder and reads back the same file
with XMLDecoder
-nowrite only reads
Tests:
With 1.4.X
- java de.gaskin.xml.test.EnDecodeBug1
- Is OK and produces "bug1.xml" in current directory
With 1.5.0 beta 1 RUN 1
- java de.gaskin.xml.test.EnDecodeBug1 -nowrite
- ERRORS reading in!!!!
With 1.5.0 beta 1 RUN 2
- java de.gaskin.xml.test.EnDecodeBug1 -nowrite
- ERRORS writing out
*/
public class EnDecodeBug1 {
Obj[] array;
Obj[][] array2D;
public EnDecodeBug1() {
}
public EnDecodeBug1(Obj[] array) {
this.array = array;
}
public void setArray(Obj[] array) {
this.array = array;
}
public Obj[] getArray() {
return array;
}
public void setArray2D(Obj[][] array2D) {
this.array2D = array2D;
}
public Obj[][] getArray2D() {
return array2D;
}
public void encode(String filename) throws FileNotFoundException {
XMLEncoder encoder = new XMLEncoder(new FileOutputStream(filename));
encoder.writeObject(this);
encoder.close();
}
public void list() {
list(array, "");
if (array2D != null) {
int loopCnt = array2D.length;
for (int i = 0;i < loopCnt;i++) {
String prefix = "[" + i + "]";
list(array2D[i], prefix);
}
}
else {
System.err.println("'array2D' is 'null' BUT SHOULD NOT BE NULL!!!");
}
}
public void list(Obj[] array, String prefix) {
if (array != null) {
int loopCnt = array.length;
for (int i = 0;i < loopCnt;i++) {
System.err.println(prefix + array[i]);
}
}
}
public static EnDecodeBug1 decode(String filename)
throws FileNotFoundException {
XMLDecoder decoder = new XMLDecoder(new FileInputStream(filename));
EnDecodeBug1 rc = (EnDecodeBug1)decoder.readObject();
decoder.close();
return rc;
}
public static class Obj {
String attr;
public Obj() {
}
public Obj(String attr) {
this.attr = attr;
}
public void setAttr(String attr) {
this.attr = attr;
}
public String getAttr() {
return attr;
}
public String toString() {
return attr;
}
}
public static void main(String[] args) throws Exception {
String filename = "bug1.xml";
boolean write = true;
if (args.length > 0) {
if (args[0].charAt(0) == '-') {
if (args[0].equals("-nowrite")) {
write = false;
if (args.length > 1) {
filename = args[1];
}
}
else {
System.err.println("Only known switch is '-nowrite' ABORT");
System.exit(-1);
}
}
else {
filename = args[0];
}
}
if (write) {
Obj[] array = new Obj[2];
array[0] = new Obj("one");
array[1] = new Obj("two");
Obj[][] array2D = {
array,
};
EnDecodeBug1 test = new EnDecodeBug1(array);
test.setArray2D(array2D);
test.encode(filename); ;
test.list();
}
System.err.println("And now read back");
EnDecodeBug1 test1 = EnDecodeBug1.decode(filename);
test1.list();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Don't use multidimensional arrays with XMLEncoder/XMLDecoder
Release Regression From : 1.4.2
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
(Incident Review ID: 237793)
======================================================================