JDK-8069098 : StAX produces the wrong event stream
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.stream
  • Affected Version: 8
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2015-01-15
  • Updated: 2017-05-17
  • Resolved: 2016-10-31
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.
JDK 9
9 b143Fixed
Related Reports
Relates :  
Description
The default StAX parser does not produce the correct events when the input document is:

<?xml-stylesheet href="bar.xsl" type="text/xsl"?>
<foo/>

In this case, the XMLStreamReader (com.sun.xml.internal.stream.XMLInputFactoryImpl) starts on a PROCESSING_INSTRUCTION event.  Instead, it should start on a START_DOCUMENT event.

 From JSR 173, 1.0, Section 5.1, XMLStreamReader:
"At any moment in time an XMLStreamReader instance has a current event that the methods of the interface access. Instances are created in the START_DOCUMENT state and this is set to the current event type."

Here is a reproducer:

---------- BEGIN SOURCE ----------
import java.io.StringReader;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamReader;

public class TestStAX {

   public static void main(String[] args) throws Exception {
       String xml = "<?xml-stylesheet href=\"bar.xsl\" type=\"text/xsl\"?>" +
                    "<foo/>";
       XMLInputFactory factory = XMLInputFactory.newFactory();

       // class com.sun.xml.internal.stream.XMLInputFactoryImpl
       System.err.println(factory.getClass());
       XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(xml));

       // prints false, should print true
       System.err.println(reader.getEventType() == XMLStreamConstants.START_DOCUMENT);

       // prints true, should print false
       System.err.println(reader.getEventType() == XMLStreamConstants.PROCESSING_INSTRUCTION);

       // From JSR 173, 1.0, Section 5.1, XMLStreamReader:
       //  "At any moment in time an XMLStreamReader instance has a current event that the
       //   methods of the interface access. Instances are created in the START_DOCUMENT
       //   state and this is set to the current event type."
   }

}
---------- END SOURCE ----------





Comments
Prioritize it as you see fit. I am just pointing out that the parser produces incorrect results in a common case and that I don't consider this a minor problem.
06-06-2016

It is a P4 by the mapping rules, and as you correctly set when you created the bug. If you have a business case and need it fixed sooner, or in JDK 8, you'll need to create a support request.
03-06-2016

It looks like the tag "tbd_minor" has been added to this bug? I disagree that this bug is minor. Processing instructions at the beginning of a document aren't uncommon. e.g. https://www.w3.org/TR/xml-stylesheet/#introduction In such cases, the output of this parser is incorrect.
25-05-2016