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

isEqualNode() returns true in case of different document types

XMLWordPrintable

    • 1.3
    • generic
    • generic
    • Verified

      Name: eaR10174 Date: 08/29/2003


        The method Node.isEqualNode() returns true in case when two document types with
      different internal subsets are compared (see test.java below). According to the method
      javadoc:

         For two DocumentType nodes to be equal, the following conditions must also be
         satisfied:

          * The following string attributes are equal: publicId, systemId, internalSubset.
          * The entities NamedNodeMaps are equal.
          * The notations NamedNodeMaps are equal.

      the method should return false.

        The bug appears in jdk1.5.0beta-b16 and affects a new JCK1.5 test:

           api/org_w3c/dom/Node/index.html#IsEqualNode[IsEqualNode011]

      ------------------------------------test.java-----------------------------
      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.parsers.DocumentBuilder;
      import org.xml.sax.InputSource;
      import org.w3c.dom.Document;
      import org.w3c.dom.DocumentType;
      import java.io.StringReader;

      public class test {

          String data1 =
              "<?xml version=\"1.0\" ?>"
            + "<!DOCTYPE test [\n"
            + "ENTITY entity1 'entity1'"
            + "ENTITY entity2 'entity2'"
            + "ELEMENT root (#PCDATA)"
            + "]>"
            + "<root>&entity1; &entity2;</root>";

          String data2 =
              "<?xml version=\"1.0\" ?>"
            + "<!DOCTYPE test [\n"
            + "ENTITY entity1 'entity1'"
            + "ENTITY entity3 'entity3'" // another entity defined
            + "ELEMENT root (#PCDATA)"
            + "]>"
            + "<root>&entity1; &entity3;</root>";
            
          DocumentBuilder docBuilder = null;

          public static void main(String argv[]) {
              new test().run();
          }
          
          public void run() {
              try {
                  DocumentBuilderFactory docBF = DocumentBuilderFactory.newInstance();
                  docBF.setNamespaceAware(true);
                  docBuilder = docBF.newDocumentBuilder();
                  
                  DocumentType docType1 = parse(data1).getDoctype();
                  DocumentType docType2 = parse(data2).getDoctype();

                  if (docType1.isEqualNode(docType2)) {
                      System.out.println("isEqualNode returns true.");
                  } else {
                      System.out.println("OK.");
                  }
              } catch (Exception e) {
                  e.printStackTrace();
                  return;
              }

          }
          
          private Document parse(String xmlData) throws Exception {
               StringReader in = new StringReader(xmlData);
               InputSource source = new InputSource(in);
               return docBuilder.parse(source);
          }
      }
      --------------------------------------------------------------------------
      % java -showversion test
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b16)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b16, mixed mode)

      isEqualNode returns true.
      --------------------------------------------------------------------------

      ======================================================================
      ###@###.### 2003-09-03

            kkawagucsunw Kohsuke Kawaguchi (Inactive)
            evgsunw Evg Evg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: