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

node.setNodeValue() doesn't throw DOMException if node is readonly

XMLWordPrintable

    • 1.2.0
    • generic
    • generic



      Name: eaR10174 Date: 11/08/2001


        The method org.w3c.dom.Node.setNodeValue() does not throw the DOMexception with
      NO_MODIFICATION_ALLOWED_ERR error code in case when a node is readonly, i.e., the node is
      either Entity or Notation or EntityReference or DocumentType node (See test.java below).

        The javadoc description (build jdk1.4.0beta-b84) of this method reads:
        
          "public void setNodeValue(String nodeValue)
                        throws DOMException

           ...
           Throws:
               DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly."

        This bug is found in the builds jdk1.4.0-beta3-b84, jaxp-1.1.3-b02-30_oct_2001 and
      affects the new JCK1.4 test
        
      api/org_w3c/dom/Node/index.html#SetGetNodeValue[SetGetNodeValue011]

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

      public class test {
         private static final String XML_DATA =
                  "<?xml version=\"1.0\" ?>"
                  + "<!DOCTYPE root ["
                  + "<!ELEMENT root ANY>"
                  + "<!ENTITY ent \"foo\">"
                  + "<!NOTATION not PUBLIC \"http://xxx.xxx.xx/x.txt\">"
                  + "]>"
                  + "<root>"
                  + "</root>";

          private static EntityReference entityRef;
          private static Entity entity;
          private static Notation notation;
          private static DocumentType docType;

          public static void main (String[] args) {
              try {
                  init();
              } catch (Exception e) {
                  System.out.println(e);
                  System.exit(1);
              }
              
              System.out.println("Test EntityReference:");
              testReadonlyNode(entityRef);
              System.out.println("");

              System.out.println("Test Entity:");
              testReadonlyNode(entity);
              System.out.println("");

              System.out.println("Test Notation:");
              testReadonlyNode(notation);
              System.out.println("");

              System.out.println("Test DocumentType:");
              testReadonlyNode(docType);
              System.out.println("");
          }
          
          private static void init() throws Exception {
              DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance()
                                               .newDocumentBuilder();

              StringReader in = new StringReader(XML_DATA);
              InputSource source = new InputSource(in);
              Document document = docBuilder.parse(source);
          
              entityRef = document.createEntityReference("AEntRef");
              docType = document.getDoctype();
              entity = (Entity)docType.getEntities().item(0);
              notation = (Notation)docType.getNotations().item(0);
          }
          
          private static void testReadonlyNode(Node node) {
              try {
                  node.setNodeValue("test");

                  System.out.println("DOMException not thrown");
              } catch (DOMException e) {
                  if (e.code != DOMException.NO_MODIFICATION_ALLOWED_ERR) {
                      System.out.println("Wrong error code");
                  } else {
                      System.out.println("OK");
                  }
              }
          }
      }
      ---------------------------------------------------------------------------
      ---------------------------------------------------------------------------
      % java -showversion test
      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)

      Test EntityReference:
      DOMException not thrown

      Test Entity:
      DOMException not thrown

      Test Notation:
      DOMException not thrown

      Test DocumentType:
      DOMException not thrown

      ---------------------------------------------------------------------------

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

            duke J. Duke
            evgsunw Evg Evg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: