Dear all,

I noticed the method net.sf.hibernate.util.next() may fail under some
circumstances.
I have not encountered any situation (yet) where this happens, but the code
is not robust enough and a simple test case (on this class) can break it.

Here is the current code:

        public Object next() {
          if ( iterators[current].hasNext() ) {
            return iterators[current].next();
          }
          else {
            current++;
            return next();
          }
        }

Suppose the latest iterator of the chain is empty.
When the iterator n-1 is exhausted, the else branch is selected, the current
index is incremented to the latest, and a recursive call is made. The if
fails again, but this time the current index is incremented one step too
far, causing the recursive call to faill with an IndexOutOfBoundException.

As you can see this code is easy to fix...

Don't know if the current situation can break something in Hibernate, but I
think it is safer to fix it.

On the other hand, such Iterator already exists in Jakarta Collection
library - it is called IteratorChain.
Unfortunately, it contains the same kind of bug as of its version 2.1 - the
fix will be released in 3.0 


-bertrand






-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to