You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by le...@apache.org on 2001/01/18 23:26:31 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/dom AttrImpl.java ParentNode.java

lehors      01/01/18 14:26:30

  Modified:    java/src/org/apache/xerces/dom AttrImpl.java ParentNode.java
  Log:
  fixed a couple of bugs in insertBefore:
  raise an exception if a node is being inserted as its own child, or before
  itself.
  
  Revision  Changes    Path
  1.25      +14 -4     xml-xerces/java/src/org/apache/xerces/dom/AttrImpl.java
  
  Index: AttrImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/AttrImpl.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- AttrImpl.java	2001/01/12 00:10:17	1.24
  +++ AttrImpl.java	2001/01/18 22:26:25	1.25
  @@ -118,7 +118,7 @@
    * But in the tests I've run I've seen up to 12% of memory gain. And the good
    * thing is that it also leads to a slight gain in speed because we allocate
    * fewer objects! I mean, that's until we have to actually create the node...
  - *
  + * <p>
    * To avoid too much duplicated code, I got rid of ParentNode and renamed
    * ChildAndParentNode, which I never really liked, to ParentNode for
    * simplicity, this doesn't make much of a difference in memory usage because
  @@ -127,6 +127,9 @@
    * implementation of the ParentNode's node behavior. So there is still some
    * duplicated code there.
    *
  + * <p><b>WARNING</b>: Some of the code here is partially duplicated in
  + * ParentNode, be careful to keep these two classes in sync!
  + *
    * @see AttrNSImpl
    *
    * @author Arnaud  Le Hors, IBM
  @@ -646,21 +649,28 @@
   
           if (errorChecking) {
               // Prevent cycles in the tree
  +            // newChild cannot be ancestor of this Node,
  +            // and actually cannot be this
               boolean treeSafe = true;
  -            for (NodeImpl a = parentNode();
  +            for (NodeImpl a = this;
                    treeSafe && a != null;
                    a = a.parentNode()) {
                   treeSafe = newChild != a;
               }
               if(!treeSafe) {
                   throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, 
  -                                           "DOM006 Hierarchy request error");
  +                                       "DOM006 Hierarchy request error");
               }
   
               // refChild must in fact be a child of this node (or null)
               if(refChild != null && refChild.getParentNode() != this) {
                   throw new DOMException(DOMException.NOT_FOUND_ERR,
  -                                           "DOM008 Not found");
  +                                       "DOM008 Not found");
  +            }
  +            // refChild cannot be same as newChild
  +            if(refChild == newChild) {
  +                throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, 
  +                                       "DOM006 Hierarchy request error");
               }
           }
           
  
  
  
  1.18      +14 -4     xml-xerces/java/src/org/apache/xerces/dom/ParentNode.java
  
  Index: ParentNode.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ParentNode.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ParentNode.java	2001/01/12 00:10:26	1.17
  +++ ParentNode.java	2001/01/18 22:26:26	1.18
  @@ -1,4 +1,4 @@
  -/* $Id: ParentNode.java,v 1.17 2001/01/12 00:10:26 lehors Exp $ */
  +/* $Id: ParentNode.java,v 1.18 2001/01/18 22:26:26 lehors Exp $ */
   /*
    * The Apache Software License, Version 1.1
    *
  @@ -89,6 +89,9 @@
    * case is Attribute, but we deal with there in another special way, so this is
    * not applicable.
    *
  + * <p><b>WARNING</b>: Some of the code here is partially duplicated in
  + * AttrImpl, be careful to keep these two classes in sync!
  + *
    * @author Arnaud  Le Hors, IBM
    * @author Joe Kesselman, IBM
    * @author Andy Clark, IBM
  @@ -343,21 +346,28 @@
   
           if (errorChecking) {
               // Prevent cycles in the tree
  +            // newChild cannot be ancestor of this Node,
  +            // and actually cannot be this
               boolean treeSafe = true;
  -            for (NodeImpl a = parentNode();
  +            for (NodeImpl a = this;
                    treeSafe && a != null;
                    a = a.parentNode()) {
                   treeSafe = newChild != a;
               }
               if(!treeSafe) {
                   throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, 
  -                                           "DOM006 Hierarchy request error");
  +                                       "DOM006 Hierarchy request error");
               }
   
               // refChild must in fact be a child of this node (or null)
               if(refChild != null && refChild.getParentNode() != this) {
                   throw new DOMException(DOMException.NOT_FOUND_ERR,
  -                                           "DOM008 Not found");
  +                                       "DOM008 Not found");
  +            }
  +            // refChild cannot be same as newChild
  +            if(refChild == newChild) {
  +                throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, 
  +                                       "DOM006 Hierarchy request error");
               }
           }