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

Method resolveEntity() is invoked with null systemId

    • 1.2.0
    • generic
    • generic
    • Verified



      Name: eaR10174 Date: 02/08/2002


        Method org.xml.sax.EntityResolver.resolveEntity() of application's resolver is
      invoked with null systemId during the parsing document with external DTD. The
      entity's systemId can't be null according to the XML specification.
        The bug appears in both cases when the document is parsed by either DocumentBuilder
      (see test1.java below) or SAXParser (see test2.java below).
        This bug is found in jaxp-1.2.0-beta-b06-06_feb_2002 and affects the and affects the
      tests in the JAXP 1.2 TCK (same as in JCK Merlin).
        
        api/org_w3c/dom/Entity/index.html#GetSystemId[GetSystemId002]
        api/org_w3c/dom/Entity/index.html#GetNotationName[GetNotationName003]
        api/org_w3c/dom/Document/index.html#GetDoctype[GetDoctype001]
        api/org_xml/sax/helpers/XMLFilterImpl/index.html#skippedEntity[skippedEntity001]
        api/org_xml/sax/helpers/DefaultHandler/index.html#skippedEntity[skippedEntity001]
        api/org_w3c/dom/DocumentType/index.html#GetEntities[GetEntities008]
        api/org_w3c/dom/DocumentType/index.html#GetNotations[GetNotations004]
        api/org_w3c/dom/Entity/index.html#GetPublicId[GetPublicId002]
        api/javax_xml/parsers/SAXParser/index.html#Parse[Parse060]
        api/javax_xml/parsers/SAXParser/index.html#Parse[Parse061]

      ------------------------------------test1.java-----------------------------
      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.parsers.DocumentBuilder;
      import org.xml.sax.EntityResolver;
      import org.xml.sax.InputSource;
      import org.xml.sax.SAXException;
      import java.io.StringReader;

      public class test1 {

          public static void main (String[] args) {
              String docXML = "<?xml version='1.0' standalone='no' ?>"
                            + "<!DOCTYPE seven-wonders SYSTEM 'doc_type.dtd'>"
                            + "<seven-wonders>"
                            + " <first>I'm first</first>"
                            + "</seven-wonders>";

              final String docTypeDTD = "<!ELEMENT seven-wonders (first)>"
                                      + "<!ELEMENT first (#PCDATA)>";


              try {
                  EntityResolver resolver = new EntityResolver() {
                      public InputSource resolveEntity(String publicId,
                                                       String systemId)
                              throws SAXException {
                          System.out.println("systemId: " + systemId);
                          return (systemId.equals("doc_type.dtd"))
                                  ? new InputSource(new StringReader(docTypeDTD))
                                  : null;
                      }
                  };

                  InputSource inSource = new InputSource(new StringReader(docXML));
                  inSource.setSystemId("test.xml");

                  DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance()
                      .newDocumentBuilder();
                  docBuilder.setEntityResolver(resolver);
                  docBuilder.parse(inSource);

                  System.out.println("OK: Document parsed.");
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
      ---------------------------------------------------------------------------
      % echo $CLASSPATH
      .:/home/evg/lib/dom.jar:/home/evg/lib/sax.jar:/home/evg/lib/jaxp-api.jar:/home/evg/lib
      /xalan.jar:/home/evg/lib/xercesImpl.jar

      % java -showversion test1
      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      systemId: null
      java.lang.NullPointerException
              at org.apache.xerces.parsers.DOMParser.parse(DOMParser.java:257)
              at
      org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:209)
              at test.main(test.java:39)
      ---------------------------------------------------------------------------
      ------------------------------------test2.java-----------------------------
      import javax.xml.parsers.SAXParserFactory;
      import javax.xml.parsers.SAXParser;
      import org.xml.sax.helpers.DefaultHandler;
      import org.xml.sax.InputSource;
      import org.xml.sax.SAXException;
      import java.io.StringReader;

      public class test2 {

          public static void main (String[] args) {
              String docXML = "<?xml version='1.0' standalone='no' ?>"
                            + "<!DOCTYPE seven-wonders SYSTEM 'doc_type.dtd'>"
                            + "<seven-wonders>"
                            + " <first>I'm first</first>"
                            + "</seven-wonders>";

              final String docTypeDTD = "<!ELEMENT seven-wonders (first)>"
                                      + "<!ELEMENT first (#PCDATA)>";


              try {
                  DefaultHandler handler = new DefaultHandler() {
                      public InputSource resolveEntity(String publicId,
                                                       String systemId)
                              throws SAXException {
                          System.out.println("systemId: " + systemId);
                          return (systemId.equals("doc_type.dtd"))
                                  ? new InputSource(new StringReader(docTypeDTD))
                                  : null;
                      }
                  };

                  InputSource inSource = new InputSource(new StringReader(docXML));
                  inSource.setSystemId("test.xml");

                  SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
                  parser.parse(inSource, handler);

                  System.out.println("OK: Document parsed.");
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
      ---------------------------------------------------------------------------
      ---------------------------------------------------------------------------
      % echo $CLASSPATH
      .:/home/evg/lib/dom.jar:/home/evg/lib/sax.jar:/home/evg/lib/jaxp-api.jar:/home/evg/lib
      /xalan.jar:/home/evg/lib/xercesImpl.jar

      % java -showversion test2
      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      systemId: null
      java.lang.NullPointerException
              at
      org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1193)
              at javax.xml.parsers.SAXParser.parse(Unknown Source)
              at test.main(test.java:37)
      ---------------------------------------------------------------------------

      ======================================================================

            nbajajsunw Neeraj Bajaj (Inactive)
            evgsunw Evg Evg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: