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

REGRESSION: JAXP - DocumentType object always null

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.3
    • CPU:
      x86
    • OS:
      windows_xp

      Backports

        Description

        Name: gm110360 Date: 05/10/2004


        FULL PRODUCT VERSION :
        java version "1.5.0-beta"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
        Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows XP [Version 5.1.2600]

        A DESCRIPTION OF THE PROBLEM :
        getDocType() method for Document object always returns null, even though a DOCTYPE declaration is present.
        (Note: Bug reporting has not provision for identifying JAXP with SDK1.5)

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the sample code

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Non-null DocumentType reference and listing of the document nodes according to the DTD.
        ACTUAL -
        DocumentType node is null - should be non-null.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import javax.xml.parsers.DocumentBuilderFactory;
        import javax.xml.parsers.DocumentBuilder;
        import javax.xml.parsers.ParserConfigurationException;
        import org.xml.sax.SAXException;
        import org.xml.sax.ErrorHandler;
        import org.xml.sax.SAXParseException;
        import org.w3c.dom.Document;
        import org.w3c.dom.DocumentType;
        import org.w3c.dom.NodeList;
        import org.w3c.dom.Node;
        import java.io.File;
        import java.io.IOException;

        public class TryDOM implements ErrorHandler {
          public static void main(String args[]) {
            if(args.length == 0) {
              System.out.println("No file to process."+
                                   "Usage is:\njava TryDOM \"filename\"");
                                   
              System.exit(1);
            }
            File xmlFile = new File(args[0]);
            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
            builderFactory.setNamespaceAware(true); // Set namespace aware
            builderFactory.setValidating(true); // and validating parser feaures

            DocumentBuilder builder = null;
            try {
              builder = builderFactory.newDocumentBuilder(); // Create the parser
              builder.setErrorHandler(new TryDOM()); //Error handler is instance of TryDOM
            }
            catch(ParserConfigurationException e) {
              e.printStackTrace();
            }
            Document xmlDoc = null;

            try {
              xmlDoc = builder.parse(xmlFile);
            }
            catch(SAXException e) {
              e.printStackTrace();
            }
            catch(IOException e) {
              e.printStackTrace();
            }
            DocumentType doctype = xmlDoc.getDoctype(); // Get the DOCTYPE node
            System.out.println("DOCTYPE node:\n" + doctype); // and output it
            System.out.println("\nDocument body contents are:");
            listNodes(xmlDoc.getDocumentElement(),""); // Root element & children
          }
          
          // output a node and all its child nodes
          static void listNodes(Node node, String indent) {
            String nodeName = node.getNodeName();
            System.out.println(indent+nodeName+" Node, type is "
                                                     +node.getClass().getName()+":");
            System.out.println(indent+" "+node);

            NodeList list = node.getChildNodes(); // Get the list of child nodes
            if(list.getLength() > 0) { // As long as there are some...
              System.out.println(indent+"Child Nodes of "+nodeName+" are:");
              for(int i = 0 ; i<list.getLength() ; i++) //...list them & their children...
                listNodes(list.item(i),indent+" "); // by calling listNodes() for each
            }
          }

          public void fatalError(SAXParseException spe) throws SAXException {
            System.out.println("Fatal error at line "+spe.getLineNumber());
            System.out.println(spe.getMessage());
            throw spe;
          }

          public void warning(SAXParseException spe) {
            System.out.println("Warning at line "+spe.getLineNumber());
            System.out.println(spe.getMessage());
          }

          public void error(SAXParseException spe) {
            System.out.println("Error at line "+spe.getLineNumber());
            System.out.println(spe.getMessage());
          }
        }

        /* Document:
        <?xml version="1.0"?>
        <!DOCTYPE address SYSTEM "AddressDoc.dtd">
        <address>
          <buildingnumber> 29 </buildingnumber>
          <street> South Lasalle Street</street>
          <city>Chicago</city>
          <state>Illinois</state>
          <zip>60603</zip>
        </address>
        */

        /* DTD:
        ELEMENT address (buildingnumber, street, city, state, zip)
        ELEMENT buildingnumber (#PCDATA)
        ELEMENT street (#PCDATA)
        ELEMENT city (#PCDATA)
        ELEMENT state (#PCDATA)
        ELEMENT zip (#PCDATA)
        */


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

        Release Regression From : 1.2.0
        The above release value was the last known release where this
        bug was known to work. Since then there has been a regression.

        (Incident Review ID: 261460)
        ======================================================================
        ###@###.### 2004-05-11

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                vkorcl Venugopal K (Inactive)
                Reporter:
                gmanwanisunw Girish Manwani (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: