-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
1.4.1
-
Fix Understood
-
x86
-
windows_2000
Name: gm110360 Date: 03/21/2003
FULL PRODUCT VERSION :
a -version
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
%
FULL OPERATING SYSTEM VERSION : Windows 2000
5.00.2195
A DESCRIPTION OF THE PROBLEM :
XMLEncoder does not store arrays of things
in beans persisted with it. The example below shows
a string array; although, the problem happens
with other types of arrays.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. run the sample code below
2.
3.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expect string array to be written and
restored
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.beans.*;
import java.io.*;
public class Test {
public static void main(String[] args) {
new Test();
}
public Test() {
TestBean bean = new TestBean();
int i;
for (i=0; i<4; i++)
bean.setThing(i, "BAR"+Integer.toString(i));
for (i=0; i<4; i++)
System.out.println(bean.getThing(i));
FileOutputStream fin = null;
BufferedOutputStream bos = null;
XMLEncoder xe = null;
try {
fin = new FileOutputStream("test.ser");
bos = new BufferedOutputStream(fin);
xe = new XMLEncoder(bos);
System.out.println(bean.getClass().getName());
xe.writeObject(bean);
} catch (Exception e) {
e.printStackTrace();
return;
} finally {
try {
if (xe != null) {
xe.flush();
xe.close();
}
if (bos != null)
bos.close();
if (fin != null)
fin.close();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
FileInputStream in = null;
BufferedInputStream s = null;
XMLDecoder xd = null;
Object o = null;
try {
in = new FileInputStream("test.ser");
s = new BufferedInputStream(in);
xd = new XMLDecoder(s);
o = xd.readObject();
} catch (Exception e) {
e.printStackTrace();
return;
} finally {
try {
if (xd != null)
xd.close();
if (s != null)
s.close();
if (in != null)
in.close();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
for (i=0; i<4; i++)
System.out.println(((TestBean)o).getThing(i));
}
}
public class TestBean implements java.io.Serializable {
String [] fob = { "a", "b", "c", "d" };
public TestBean() {
}
public void setThing(int i, String x) {
fob[i] = x;
}
public String getThing(int i) {
return fob[i];
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
None I can tell
(Review ID: 153486)
======================================================================
FULL PRODUCT VERSION :
a -version
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
%
FULL OPERATING SYSTEM VERSION : Windows 2000
5.00.2195
A DESCRIPTION OF THE PROBLEM :
XMLEncoder does not store arrays of things
in beans persisted with it. The example below shows
a string array; although, the problem happens
with other types of arrays.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. run the sample code below
2.
3.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expect string array to be written and
restored
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.beans.*;
import java.io.*;
public class Test {
public static void main(String[] args) {
new Test();
}
public Test() {
TestBean bean = new TestBean();
int i;
for (i=0; i<4; i++)
bean.setThing(i, "BAR"+Integer.toString(i));
for (i=0; i<4; i++)
System.out.println(bean.getThing(i));
FileOutputStream fin = null;
BufferedOutputStream bos = null;
XMLEncoder xe = null;
try {
fin = new FileOutputStream("test.ser");
bos = new BufferedOutputStream(fin);
xe = new XMLEncoder(bos);
System.out.println(bean.getClass().getName());
xe.writeObject(bean);
} catch (Exception e) {
e.printStackTrace();
return;
} finally {
try {
if (xe != null) {
xe.flush();
xe.close();
}
if (bos != null)
bos.close();
if (fin != null)
fin.close();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
FileInputStream in = null;
BufferedInputStream s = null;
XMLDecoder xd = null;
Object o = null;
try {
in = new FileInputStream("test.ser");
s = new BufferedInputStream(in);
xd = new XMLDecoder(s);
o = xd.readObject();
} catch (Exception e) {
e.printStackTrace();
return;
} finally {
try {
if (xd != null)
xd.close();
if (s != null)
s.close();
if (in != null)
in.close();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
for (i=0; i<4; i++)
System.out.println(((TestBean)o).getThing(i));
}
}
public class TestBean implements java.io.Serializable {
String [] fob = { "a", "b", "c", "d" };
public TestBean() {
}
public void setThing(int i, String x) {
fob[i] = x;
}
public String getThing(int i) {
return fob[i];
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
None I can tell
(Review ID: 153486)
======================================================================