Details
Description
Hi,
following up on our discussion about XStream's thread safety on the mailing list, I found a problem when calling createObjectOutputStream() and toXML() concurrently. I'll attach a minimal example, see below for the stack trace.
According to your explanations about the thread safety that XStream guarantees, this seems a clear bug.
Thanks!
Exception in thread "Thread-4154" java.lang.NullPointerException
at com.sun.xml.internal.stream.writers.UTF8OutputStreamWriter.write(UTF8OutputStreamWriter.java:94)
at com.sun.xml.internal.stream.writers.UTF8OutputStreamWriter.write(UTF8OutputStreamWriter.java:129)
at com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.writeStartDocument(XMLStreamWriterImpl.java:1109)
at com.thoughtworks.xstream.io.xml.StaxWriter.<init>(StaxWriter.java:74)
at com.thoughtworks.xstream.io.xml.StaxDriver.createStaxWriter(StaxDriver.java:141)
at com.thoughtworks.xstream.io.xml.StaxDriver.createStaxWriter(StaxDriver.java:145)
at com.thoughtworks.xstream.io.xml.StaxDriver.createWriter(StaxDriver.java:129)
at com.thoughtworks.xstream.XStream.createObjectOutputStream(XStream.java:1575)
at XStreamTest6$1.run(XStreamTest6.java:24)
at java.lang.Thread.run(Thread.java:619)
Hmm. I cannot reproduce this, your test runs through. Since the error actually happens in the JDK's StAX implementation, can you use a recent version of the JDK?
========= %< ======
$ java -version
java version "1.6.0_27"
Java(TM) SE Runtime Environment (build 1.6.0_27-b07)
Java HotSpot(TM) Server VM (build 20.2-b06, mixed mode)
$ uname -a
Linux josix 2.6.39-gentoo-r3 #2 SMP PREEMPT Fri Sep 9 10:04:29 CEST 2011 i686 Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz GenuineIntel GNU/Linux
========= %< ======
I'll try it with a different machine later on.