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

StAX XMLOutputFactory createXMLStreamWriter() only supports Stream Results

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 6u11
    • xml
    • h1164
    • generic
    • generic
    • Verified

        OPERATING SYSTEM
        ----------------
        Windows

        FULL JDK VERSION
        ----------------
        StAX in JDK 1.6.0_11

        DESCRIPTION
        -----------
        It appears the StAX XMLOutputFactory createXMLStreamWriter(javax.xml.transform.Result) only supports Stream Results.

        However, this is neither documented nor enforced. I've attached BadResultTest.java which creates an XMLStreamWriter from a SAXResult. As documented in the test case, writing to thisnew XMLStreamWriter will result in a NullPointerException.

        TESTCASE SOURCE
        ---------------
        import javax.xml.stream.XMLEventWriter;
        import javax.xml.stream.XMLStreamWriter;
        import javax.xml.transform.sax.SAXResult;

        public class BadResultTest extends org.xml.sax.ext.DefaultHandler2 {
            public static void main (String[] args) throws Exception {
                javax.xml.stream.XMLOutputFactory factory = javax.xml.stream.XMLOutputFactory.newInstance ();

                SAXResult saxResult= new SAXResult(new BadResultTest());

                //I believe this should either store away the SAXResult
                //Or throw an UnsupportedOperationException
                //Clearly, it's expecting an Outputstream, which doesn't exist in the SAXResult
                XMLStreamWriter writer = factory.createXMLStreamWriter (saxResult);

                //tries to write to non-existant stream and throws NullPointerException
                writer.writeStartDocument ();

                System.out.println("Success");
            }
        }

              joehw Joe Wang
              dkorbel David Korbel (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: