JDK-8169450 : StAX parse error if there is a newline in xml declaration
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.stream
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-11-09
  • Updated: 2020-01-29
  • Resolved: 2017-02-14
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 10 JDK 9
10Fixed 9 b158Fixed
Related Reports
Relates :  
Relates :  
Description
ParseError will happen during StAX parse the follow xml:
<?xml
 version="1.0"?>
<root>
 <test>t</test>
</root>

Run the following java program:
import java.io.File;
import java.io.FileReader;

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

public class Test8169450 {
    public static void main(String[] args) throws Exception {
        File file = new File("test.xml");

/*      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(true);
        DocumentBuilder db = dbf.newDocumentBuilder();
        db.parse(file); */
        
        XMLStreamReader reader = XMLInputFactory.newFactory().createXMLStreamReader(new FileReader(file));
        while (reader.hasNext()) {
            reader.next();
        }
    }
}

It will throw exception:
Exception in thread "main" javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,11]
Message: The processing instruction target matching "[xX][mM][lL]" is not allowed.
	at java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:596)
	at Test8169450.main(Test8169450.java:20)

This issue should be caused by JDK-8069098.