Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Won't Fix
-
Affects Version/s: 1.4.2
-
Fix Version/s: None
-
Component/s: Core
-
Labels:None
-
JDK version and platform:Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode)
Description
I sent the following stack trace in email before realizing that I should file a bug instead.
Using this program:
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver; import java.util.Map; public class XstreamTest { private static XStream createXStream() { XStream xstream = new XStream(new JettisonMappedXmlDriver()); xstream.setMode(XStream.NO_REFERENCES); xstream.autodetectAnnotations(false); xstream.alias("state", Map.class); return xstream; } public static void main(String[] argv) { XStream xstream = createXStream(); String s = "{\"xxx.xxxxxxx.xx.xxxxxxxx.xxxxxxx.xxxxxxxxxxxxxx\":[{\"map\":[{\"entry\":[{\"string\":[\"v\","; System.out.println(s); Object o = xstream.fromXML(s); } }
I get this output/exception:
{"xxx.xxxxxxx.xx.xxxxxxxx.xxxxxxx.xxxxxxxxxxxxxx":[{"map":[{"entry":[{"string":["v", Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:2760) at java.util.Arrays.copyOf(Arrays.java:2734) at java.util.ArrayList.ensureCapacity(ArrayList.java:167) at java.util.ArrayList.add(ArrayList.java:351) at org.codehaus.jettison.json.JSONArray.<init>(JSONArray.java:107) at org.codehaus.jettison.json.JSONTokener.nextValue(JSONTokener.java:313) at org.codehaus.jettison.json.JSONObject.<init>(JSONObject.java:195) at org.codehaus.jettison.json.JSONTokener.nextValue(JSONTokener.java:310) at org.codehaus.jettison.json.JSONArray.<init>(JSONArray.java:110) at org.codehaus.jettison.json.JSONTokener.nextValue(JSONTokener.java:313) at org.codehaus.jettison.json.JSONObject.<init>(JSONObject.java:195) at org.codehaus.jettison.json.JSONTokener.nextValue(JSONTokener.java:310) at org.codehaus.jettison.json.JSONArray.<init>(JSONArray.java:110) at org.codehaus.jettison.json.JSONTokener.nextValue(JSONTokener.java:313) at org.codehaus.jettison.json.JSONObject.<init>(JSONObject.java:195) at org.codehaus.jettison.json.JSONTokener.nextValue(JSONTokener.java:310) at org.codehaus.jettison.json.JSONArray.<init>(JSONArray.java:110) at org.codehaus.jettison.json.JSONTokener.nextValue(JSONTokener.java:313) at org.codehaus.jettison.json.JSONObject.<init>(JSONObject.java:195) at org.codehaus.jettison.mapped.MappedXMLInputFactory.createXMLStreamReader(MappedXMLInputFactory.java:43) at org.codehaus.jettison.AbstractXMLInputFactory.createXMLStreamReader(AbstractXMLInputFactory.java:151) at com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver.createReader(JettisonMappedXmlDriver.java:85) at com.thoughtworks.xstream.XStream.fromXML(XStream.java:912) at com.thoughtworks.xstream.XStream.fromXML(XStream.java:903) at XstreamTest.main(XstreamTest.java:25)
I fear there's not a lot that XStream can do here. If you look at the stack trace, you see that Jettison gets confused by this input. I am quite sure I can provoke this behavior using Jettison only. Can you confirm that you're using Jettison 1.2 (that's what XStream has been tested with)?
There are newer Jettison versions (latest 1.3.1), you may give it a try instead. However, from a short test I had to recognize that this version breaks XStream's unit tests, because it produces now a slightly different JSON structure which means in consequence the structure it can read is also different now.