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

xml class SAXParser does not call endDocument after SAXException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 6
    • xml
    • Fix Understood
    • x86
    • linux

      FULL PRODUCT VERSION :
      java version "1.6.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-beta2-b72)
      Java HotSpot(TM) Client VM (build 1.6.0-beta2-b72, mixed mode, sharing)

      NB: also occurs on 1.5.0_04

      ADDITIONAL OS VERSION INFORMATION :
      Linux blackbox 2.6.8-2-686 #1 Tue Aug 16 13:22:48 UTC 2005 i686 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      According to the javadoc for org.xml.sax.ContentHandler#endDocument, the endDocument method should be called even when "an unrecoverable error" has occurred during parsing.

      The XML parser bundled with sun java 1.5.0 and 1.6-beta2 does not do this; when SAXException is thrown by a ContentHandler implementation the endDocument method is never called.

      The Kaffe 1.1.6 JVM (which uses the Aelfred parser I believe) *does* call endDocument when a SAXException is thrown by a ContentHandler method.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See attached testclass. To run:
         java -cp . ParseTest

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      output:
        --endDocumentCalled:true
      ACTUAL -
      output:
        --endDocumentCalled:false

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      // filename: ParseTest.java

      import java.io.StringReader;
      import java.io.InputStream;
      import java.io.Reader;

      import javax.xml.parsers.SAXParser;
      import javax.xml.parsers.SAXParserFactory;

      import org.xml.sax.Attributes;
      import org.xml.sax.ContentHandler;
      import org.xml.sax.EntityResolver;
      import org.xml.sax.ErrorHandler;
      import org.xml.sax.InputSource;
      import org.xml.sax.Locator;
      import org.xml.sax.SAXException;
      import org.xml.sax.SAXNotRecognizedException;
      import org.xml.sax.SAXNotSupportedException;
      import org.xml.sax.SAXParseException;
      import org.xml.sax.XMLReader;
      import org.xml.sax.helpers.DefaultHandler;



      public class ParseTest extends DefaultHandler {
        private boolean endDocumentCalled = false;

        public static void main(String[] args) throws Exception {
          String inputXML = "<root><item/></root>";
          Reader reader = new StringReader(inputXML);

          SAXParserFactory factory = SAXParserFactory.newInstance();
          SAXParser parser = factory.newSAXParser();

          InputSource source = new InputSource(reader);
          ParseTest handler = new ParseTest();
          try {
            parser.parse(source, handler);
          } catch(SAXException ex) {
            // ok, expected
            System.out.println("exception caught");
          }

          if (handler.endDocumentCalled) {
            System.out.println("--endDocumentCalled:true");
          } else {
            System.out.println("--endDocumentCalled:false");
          }
        }

        public void endElement(String uri, String localName, String qname) throws SAXException {
          throw new SAXException("a problem occurred");
        }

        public void endDocument() {
          this.endDocumentCalled = true;
          System.out.println("END DOCUMENT CALLED");
        }
      }

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

            nwalshsunw Norman Walsh (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: