Pardon if this has already been reported, but there is a bug in the
implemenation of dom4j-0.8's FilterIterator.  The current implementation
depends on hasNext() and next() being called alternately.  Multiple
consecutive calls to hasNext() will silently advance the reference to
the next element object.  This is contrary to the way, e.g., ArrayList,
operates.

Below is a patch to address the problem.  By the way, thanks for dom4j.

--- /home/jwd/autosave/FilterIterator.java~    Mon Jul 30 14:30:30 2001
+++ FilterIterator.java    Sat Aug  4 09:17:23 2001
@@ -31,6 +31,8 @@
         if ( proxy == null ) {
             return false;
         }
+        if (next != null)
+            return true;
         while (proxy.hasNext()) {
             next = proxy.next();
             if ( matches(next) ) {
@@ -43,7 +45,9 @@
     }
 
     public Object next() {
-        return next;
+        Object toReturn = next;
+        next = null;
+        return toReturn;
     }
 
     public void remove() {




_______________________________________________
dom4j-dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to