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

schema validation fails when re-use DocumentBuilder

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 6u3
    • Fix Version/s: 1.4.0
    • Component/s: xml
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.4
    • CPU:
      sparc
    • OS:
      solaris_9
    • Verification:
      Verified

      Backports

        Description

        FULL PRODUCT VERSION :
        jrockit 1.6.
        I believe the jdk1.6 has the same issue.

        A DESCRIPTION OF THE PROBLEM :
        When I re-use DocumentBuilder instance to parse multiple xmls against schema, schema validation will report an error to ErrorHandler. Here is the error message:

        org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'env:Envelope'.

        I debuged for this issue, the error is reported at XMLSchemaValidator line 1887 because schema grammar is not found at line 1753.
        When the same parser is invoked the second time, XMLSchemaLoader instance will be reset() and schema grammar bucket will also be cleared, but the bucket cannot be filled later.

        It seems to me that the following code in XMLSchemaLoader.java must be changed:

                boolean parser_settings;
                try {
                    parser_settings = componentManager.getFeature(PARSER_SETTINGS);
                }
                catch (XMLConfigurationException e){
                    parser_settings = true;
                }
                if (!parser_settings || !fSettingsChanged){
        ++ fJAXPProcessed = false;
                    // reinitialize grammar bucket
                    initGrammarBucket();
                    return;
                }



        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        run this java application:

        package root;

        import java.io.File;
        import java.io.IOException;

        import javax.xml.parsers.DocumentBuilder;
        import javax.xml.parsers.DocumentBuilderFactory;
        import javax.xml.parsers.ParserConfigurationException;

        import org.xml.sax.ErrorHandler;
        import org.xml.sax.SAXException;
        import org.xml.sax.SAXParseException;

        /**
         * @author Adam Lee
         *
         */
        public class MultiParsing implements ErrorHandler {

          public static void main(String[] args) {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
            dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "D:\\_MyWork\\Misc\\patch\\classes\\soap-envelope.xsd");
            dbf.setNamespaceAware(true);
            dbf.setValidating(true);
            DocumentBuilder db;
            try {
              db = dbf.newDocumentBuilder();
              db.setErrorHandler(new MultiParsing());

              System.out.println(db.parse(new File("D:\\_MyWork\\Misc\\patch\\classes\\NewFile.xml")).getFirstChild());
              db.reset();
              db.setErrorHandler(new MultiParsing());
              System.out.println(db.parse(new File("D:\\_MyWork\\Misc\\patch\\classes\\NewFile.xml")).getFirstChild());
            } catch (ParserConfigurationException e) {
              e.printStackTrace();
            } catch (SAXException e) {
              e.printStackTrace();
            } catch (IOException e) {
              e.printStackTrace();
            }

          }
          public void error(SAXParseException exception) throws SAXException {
            System.out.print("error ");
            exception.printStackTrace();
          }
          public void fatalError(SAXParseException exception) throws SAXException {
            System.out.print("error ");
            exception.printStackTrace();
          }
          public void warning(SAXParseException exception) throws SAXException {
            System.out.print("error ");
            exception.printStackTrace();
          }
        }



        ERROR MESSAGES/STACK TRACES THAT OCCUR :
         org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'env:Envelope'.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1887)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:685)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:626)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3084)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:912)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:645)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:508)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
        at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
        at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
        at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208)
        at root.MultiParsing.main(MultiParsing.java:37)


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        /**
         *
         */
        package root;

        import java.io.File;
        import java.io.IOException;

        import javax.xml.parsers.DocumentBuilder;
        import javax.xml.parsers.DocumentBuilderFactory;
        import javax.xml.parsers.ParserConfigurationException;

        import org.xml.sax.ErrorHandler;
        import org.xml.sax.SAXException;
        import org.xml.sax.SAXParseException;

        /**
         * @author Adam Lee
         *
         */
        public class MultiParsing implements ErrorHandler {

          public static void main(String[] args) {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
            dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "D:\\_MyWork\\Misc\\patch\\classes\\soap-envelope.xsd");
            dbf.setNamespaceAware(true);
            dbf.setValidating(true);
            DocumentBuilder db;
            try {
              db = dbf.newDocumentBuilder();
              db.setErrorHandler(new MultiParsing());

              System.out.println(db.parse(new File("D:\\_MyWork\\Misc\\patch\\classes\\NewFile.xml")).getFirstChild());
              db.reset();
              db.setErrorHandler(new MultiParsing());
              System.out.println(db.parse(new File("D:\\_MyWork\\Misc\\patch\\classes\\NewFile.xml")).getFirstChild());
            } catch (ParserConfigurationException e) {
              e.printStackTrace();
            } catch (SAXException e) {
              e.printStackTrace();
            } catch (IOException e) {
              e.printStackTrace();
            }

          }
          public void error(SAXParseException exception) throws SAXException {
            System.out.print("error ");
            exception.printStackTrace();
          }
          public void fatalError(SAXParseException exception) throws SAXException {
            System.out.print("fatal ");
            exception.printStackTrace();
          }
          public void warning(SAXParseException exception) throws SAXException {
            System.out.print("warning ");
            exception.printStackTrace();
          }
        }

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

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  joehw Joe Wang
                  Reporter:
                  sbharadwsunw Srinivas Bharadwaj (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: