JDK-6600888 : ZephyrWriterFactory.java(java.net) and XMLOutputFactoryImpl (JDK6) are out of sync
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.stream
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-09-04
  • Updated: 2012-04-25
  • Resolved: 2007-12-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6 JDK 7 Other
1.4.0,OpenJDK6Fixed 6u10Fixed 7Fixed OpenJDK6Fixed
Description
There are different versions of SJSXP. One that comes from java.net and the other one from JDK. ZephyrWriterFactory.java(java.net) changes are not there in XMLOutputFactoryImpl.java(JDK6). JAX-WS relies on certain SJSXP features for correctness and performance. However this particular change

cvs diff -r 1.4 -r 1.5  ZephyrWriterFactory.java

is not there in JDK6 version. This causes some of the multi-thread tests to fail. Attaching a test case that fails on some machines. But it is easy to see why it fails(see the above diff). The following works with sjsxp from java.net but not with JDK6.

---------------------------------------
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.StartDocument;
import javax.xml.stream.events.XMLEvent;
import java.io.*;

import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
import com.sun.xml.internal.ws.api.streaming.XMLStreamWriterFactory;

public class MultiThread {
    private static final XMLOutputFactory outputFactory =
        XMLOutputFactory.newInstance();
    private static final XMLInputFactory inputFactory =
        XMLInputFactory.newInstance();
    private static final int NO_THREADS = 3;

    public static void main(String[] args) throws Exception {
        Thread[] threads = new Thread[NO_THREADS];
        for(int i=0; i < NO_THREADS; i++) {
            threads[i] = new Thread(new MyRunnable(i));
        }
        for(int i=0; i < NO_THREADS; i++) {
            threads[i].start();
        }
        for(int i=0; i < NO_THREADS; i++) {
            threads[i].join();
        }
    }

    public static class MyRunnable implements Runnable {
        final int no;

        MyRunnable(int no) {
            this.no = no;
        }

        public void run() {
                try {
                     FileOutputStream fos = new FileOutputStream(""+no);
                     XMLStreamWriter w = getWriter(fos);
                     //System.out.println("Writer="+w+" Thread="+Thread.currentThread());
                     w.writeStartDocument();
                     w.writeStartElement("hello");
                     for(int j=0; j < 50; j++) {
                         w.writeStartElement("a"+j);
                         w.writeEndElement();
                     }
                     w.writeEndElement();
                     w.writeEndDocument();
                     w.close();
                     fos.close();

                     FileInputStream fis = new FileInputStream(""+no);
                     XMLStreamReader r = getReader(fis);
                     while(r.hasNext()) {
                         r.next();
                     }
                     r.close();
                     fis.close();
                } catch(Exception e) {
                     e.printStackTrace();
                }
        }
    }

    public static /* synchronized */ XMLStreamReader getReader(InputStream is)
        throws Exception {
        //return inputFactory.createXMLStreamReader(is);
        return XMLStreamReaderFactory.create(null, is, true);
    }

    public static /* synchronized */ XMLStreamWriter getWriter(OutputStream os)
        throws Exception {
        //return outputFactory.createXMLStreamWriter(os);
        return XMLStreamWriterFactory.createXMLStreamWriter(os);
    }

}
------------------------------
$ javac -verbose -Xbootclasspath:$JAVA_HOME/jre/lib/rt.jar MultiThread.java
$ java MultiThread
XMLOutputFactory of = XMLOutputFactory.newInstance();
        XMLStreamWriter w = of.createXMLStreamWriter(new ByteArrayOutputStream());
        System.out.println(w);

The above code throws the following exception when run with JDK6.

Exception in thread "main" java.lang.UnsupportedOperationException
        at com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.entrySet(XMLStreamWriterImpl.java:2126)
        at java.util.AbstractMap.toString(AbstractMap.java:478)
        at java.lang.String.valueOf(String.java:2827)
        at java.io.PrintStream.println(PrintStream.java:771)
        at WhichSjsxp.main(WhichSjsxp.java:21)

Comments
EVALUATION The patch is available in jaxp 1.4 on java.net.
06-09-2007