DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21625>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21625

INVALID_STATE_ERR not raised when get(Start|End)(Container|Offset) is invoked after 
detach()

           Summary: INVALID_STATE_ERR not raised when
                    get(Start|End)(Container|Offset) is invoked after
                    detach()
           Product: Xerces2-J
           Version: 2.4.0
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: DOM
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


The methods getCollapsed(), getCommonAncestorContainer(), getEndContainer(), 
getEndOffset(), getStartContainer() and getStartOffset from the Xerces DOM 
Level2 Ranges implementation, do not raise an INVALID_STATE_ERR DOM exception 
when detach() is invoked before them.   

See http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-
20001113/ranges.html#Level-2-Range-attr-collapsed.  

The following sample can be used to reproduce this:

Test.java
=========

import org.w3c.dom.*;
import org.w3c.dom.ranges.*;
import javax.xml.parsers.*;

class Test {
    public static void main (String args []) {
        Document doc = null;
        Range range;
        Node startContainer;
        
        DocumentBuilder docBuilder = null;
        try {
            docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder
(); 
            doc = docBuilder.parse("test.xml");
        } catch (Exception e) {
            System.out.println("FAIL: " + e.getMessage());
        }               

        range = ((DocumentRange)doc).createRange();
        range.detach();
        boolean bPass=false;
        String msg="Exception not thrown";
        try {
            startContainer = range.getStartContainer();
        } catch(DOMException ex) {
            if (ex.code == DOMException.INVALID_STATE_ERR)
                bPass=true;
            msg = ex.getMessage();      
        }
        
        if (bPass)
            System.out.println("PASS:  INVALID_STATE_ERR Exception thrown.");
        else    
            System.out.println("FAIL: " + msg);
    }
}



Proposed Patch:
==============

Index: ../xml4j/src/org/apache/xerces/dom/RangeImpl.java
===================================================================
RCS file: /home/cvspublic/xml-
xerces/java/src/org/apache/xerces/dom/RangeImpl.java,v
retrieving revision 1.26
diff -u -r1.26 RangeImpl.java
--- xml-xerces/java/src/org/apache/xerces/dom/RangeImpl.java    8 May 2003 
19:52:40 -0000  1.26
+++ ../xml4j/src/org/apache/xerces/dom/RangeImpl.java   15 Jul 2003 15:57:55 -
0000
@@ -108,26 +108,56 @@
     }
     
     public Node getStartContainer() {
+       if( fDetach) {
+               throw new DOMException(
+               DOMException.INVALID_STATE_ERR, 
+                DOMMessageFormatter.formatMessage
(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
+        }      
         return fStartContainer;
     }
     
     public int getStartOffset() {
+       if( fDetach) {
+               throw new DOMException(
+               DOMException.INVALID_STATE_ERR, 
+                DOMMessageFormatter.formatMessage
(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
+        }
         return fStartOffset;
     }
     
     public Node getEndContainer() {
+       if( fDetach) {
+               throw new DOMException(
+               DOMException.INVALID_STATE_ERR, 
+                DOMMessageFormatter.formatMessage
(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
+        }      
         return fEndContainer;
     }
     public int getEndOffset() {
+       if( fDetach) {
+               throw new DOMException(
+               DOMException.INVALID_STATE_ERR, 
+                DOMMessageFormatter.formatMessage
(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
+        }      
         return fEndOffset;
     }
     
     public boolean getCollapsed() {
+       if( fDetach) {
+               throw new DOMException(
+               DOMException.INVALID_STATE_ERR, 
+                DOMMessageFormatter.formatMessage
(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
+        }  
         return (fStartContainer == fEndContainer 
              && fStartOffset == fEndOffset);
     }
     
     public Node getCommonAncestorContainer(){
+       if( fDetach) {
+               throw new DOMException(
+               DOMException.INVALID_STATE_ERR, 
+                DOMMessageFormatter.formatMessage
(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
+        } 
         Vector startV = new Vector();
         Node node;
         for (node=fStartContainer; node != null;

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to