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

SAX Parser throws incorrect error on invalid xml

XMLWordPrintable

    • b134
    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_66"
      Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      This code always reproduce the bug https://bugs.openjdk.java.net/browse/JDK-8149097. Please reopen and fix it.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code specified in test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      org.xml.sax.SAXParseException
      ACTUAL -
      java.lang.InternalError

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      XML document structures must start and end within the same entity.
      Premature end of file.
      java.lang.InternalError: processing event: -1
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:506)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
      at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
      at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
      at JDK8149097.main(JDK8149097.java:17)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      import javax.xml.parsers.*;
      import org.xml.sax.*;
      import org.xml.sax.helpers.*;

      /**
       * Code to reproduce the bug <a href="https://bugs.openjdk.java.net/browse/JDK-8149097">JDK-8149097</a>.
       */
      public class JDK8149097 {

          public static void main(String[] args) {
              try {
                  String invalidXml = "<a>";
                  SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
                  saxParserFactory.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
                  SAXParser parser = saxParserFactory.newSAXParser();
                  parser.parse(new InputSource(new StringReader(invalidXml)), new DefaultHandler() {
                      @Override
                      public void fatalError(SAXParseException e) throws SAXException {
                          System.err.printf("%s%n", e.getMessage());
                      }
                  });
              } catch (Throwable e) {
                  e.printStackTrace();
              }
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use SAX Parser provided by Xerces.

            joehw Joe Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: