Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Not A Bug
-
Affects Version/s: 1.4.1
-
Fix Version/s: None
-
Component/s: IO
-
Labels:None
-
JDK version and platform:Java HotSpot Server VM "1.6.0_07"; Linux
Description
Using a JsonWriter from multiple threads can lead to exceptions that do not occur when using the writer in a single thread. I attach a minimal test case showing the problem. Executing it leads NullPointerExceptions and to IllegalWriterStateExceptions (depending on the scheduling). See the stack traces below.
Thanks for fixing this issue!
Exception in thread "Thread-1691" java.lang.NullPointerException
at com.thoughtworks.xstream.io.json.AbstractJsonWriter.handleStateTransition(AbstractJsonWriter.java:270)
at com.thoughtworks.xstream.io.json.AbstractJsonWriter.handleCheckedStateTransition(AbstractJsonWriter.java:263)
at com.thoughtworks.xstream.io.json.AbstractJsonWriter.addAttribute(AbstractJsonWriter.java:232)
at MinimalJsonWriterTest$2.run(MinimalJsonWriterTest.java:22)
at java.lang.Thread.run(Thread.java:619)
Exception in thread "Thread-1691" com.thoughtworks.xstream.io.json.AbstractJsonWriter$IllegalWriterStateException: Cannot turn from state ROOT into state NEXT_ATTRIBUTE for property y
at com.thoughtworks.xstream.io.json.AbstractJsonWriter.handleStateTransition(AbstractJsonWriter.java:279)
at com.thoughtworks.xstream.io.json.AbstractJsonWriter.handleCheckedStateTransition(AbstractJsonWriter.java:263)
at com.thoughtworks.xstream.io.json.AbstractJsonWriter.addAttribute(AbstractJsonWriter.java:232)
at MinimalJsonWriterTest$2.run(MinimalJsonWriterTest.java:22)
This is also by design. The XStream instance uses a HierarchicalStreamDriver that creates an own instance of the appropriate reader/writer for each unmarshal/marshal task. The readers and writers are not meant to be threadsafe.