XStream
  1. XStream
  2. XSTR-678

Thread safety problem of JsonWriter

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major 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)

        People

        • Assignee:
          Jörg Schaible
          Reporter:
          Michael Pradel
        • Votes:
          0 Vote for this issue
          Watchers:
          1 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: