Details
-
Type: Bug
-
Status: Closed
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.1.1
-
Component/s: None
-
Labels:None
-
JDK version and platform:Sun 1.4.2._06 on Windows
Description
I hate to file what may be a duplicate bug (to XSTR-185), but unfortunately this bug tracking system does not allow me to re-open closed issues.
Below is an example of the problem that persists with deserializing arrays. In other code, I still get ClassNotFound exception. However, in the code below, which is very simple, it just doesn't work and reports a different exception.
Try:
1. Running Foo with the command line "to" to generate and persist XML. Then, run Foo with no args to reveal the bug.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import com.thoughtworks.xstream.XStream;
public class Foo
{
private int x = 100;
public void printX()
{ System.out.println(x); } public static void toXML() throws Exception
{
XStream xstream = new XStream();
Foo[] foos = new Foo[100];
for (int i=0; i<foos.length; i++)
String theXml = xstream.toXML(foos);
PrintWriter pw = new PrintWriter(new FileWriter("tmp.dat"));
pw.println(theXml);
pw.flush();
pw.close();
}
public static void fromXML() throws Exception
{
XStream xstream = new XStream();
BufferedReader reader = new BufferedReader(new FileReader("tmp.dat"));
String theXml = "";
while (reader.ready())
Foo[] f = (Foo[])xstream.fromXML(theXml);
for (int i=0; i<f.length; i++)
}
public static void main(String[] args) throws Exception
{
if (args.length>0 && args[0].equals("to"))
else
{ fromXML(); } }
}
This is the exception I get:
> java -classpath ".;xstream-SNAPSHOT.jar;xpp3-1.1.3.4d_b4_min.jar" Foo from
Exception in thread "main" com.thoughtworks.xstream.alias.CannotResolveClassExce
ption: Foo : [LFoo;
at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.jav
a:49)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper
.java:18)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper
.java:18)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper
.java:18)
at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper
.java:28)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller
.java:95)
at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unm
arshal(ReferenceByXPathMarshallingStrategy.java:12)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:543)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:531)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:499)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:490)
at Foo.fromXML(Foo.java:38)
at Foo.main(Foo.java:50)