Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6600888

ZephyrWriterFactory.java(java.net) and XMLOutputFactoryImpl (JDK6) are out of sync

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 6
    • xml
    • 1.4
    • generic
    • generic
    • Verified

        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)

              joehw Joe Wang
              jkotamra Jitendra Kotamraju (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: