You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by pwomack <pw...@papermule.co.uk> on 2003/12/01 18:46:14 UTC
[collections] bug in IteratorChain?
The following pseudo Junit:
Integer a = new Integer(3);
Integer b = new Integer(7);
ArrayList empty = new ArrayList();
IteratorChain ic = new IteratorChain();
ic.addIterator(empty.iterator());
ic.addIterator(new SingletonIterator(a));
ic.addIterator(new SingletonIterator(b));
int tot = 0;
for(;ic.hasNext();) {
Integer anInt = (Integer)ic.next();
tot += anInt.intValue();
}
assertEquals(10, tot);
Fails. tot is actually 0.
I suspect the empty first Iterator somehow makes the whole
iteratorChain behave as if it's empty.
BugBear
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [collections] bug in IteratorChain?
Posted by pwomack <pw...@papermule.co.uk>.
Stephen Colebourne wrote:
> Unless I'm dreaming, the return was removed not added.
> Stephen
Oh double darn - you're right. I just can't read CVS diff
output.
Bug fixed.
I've semi implemented my IteratorIterator, and have made some
tidy ups in the process. Interestingly, IteratorChain could be
implemented as a simple wrapper over my IteratorIterator.
BugBear
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [collections] bug in IteratorChain?
Posted by Stephen Colebourne <sc...@btopenworld.com>.
Unless I'm dreaming, the return was removed not added.
Stephen
----- Original Message -----
From: "pwomack" <pw...@papermule.co.uk>
> Stephen Colebourne wrote:
> > I have a vague memory of something like this getting fixed once upon a
time.
> > Are you testing against the CVS version of this file or a release?
>
> Oh darn.
>
> It looks like there's a fundemental "nasty", which may require
> thought to fix.
>
> *my* fault is caused in updateCurrentIterator(),
> which returns IMMEDIATELY after setting
> currentIterator = (Iterator) iteratorChain.get(0);
>
> If this currentIterator is empty, IteratorChain.hasNext() will return
> false, and it's all over.
>
> But this "return" in updateCurrentIterator() was added as a result
> (between v1.2 and 1.3
>
http://cvs.apache.org/viewcvs/jakarta-commons/collections/src/java/org/apach
e/commons/collections/iterators/IteratorChain.java.diff?r1=1.2&r2=1.3&diff_f
ormat=h
> as result of a bug report:
>
> "fix bug pointed out bu Jonathan Carlson
> add test that demonstrates"
>
> So I guess fixing one bug has caused another.
>
> BugBear
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [collections] bug in IteratorChain?
Posted by pwomack <pw...@papermule.co.uk>.
Stephen Colebourne wrote:
> I have a vague memory of something like this getting fixed once upon a time.
> Are you testing against the CVS version of this file or a release?
Oh darn.
It looks like there's a fundemental "nasty", which may require
thought to fix.
*my* fault is caused in updateCurrentIterator(),
which returns IMMEDIATELY after setting
currentIterator = (Iterator) iteratorChain.get(0);
If this currentIterator is empty, IteratorChain.hasNext() will return
false, and it's all over.
But this "return" in updateCurrentIterator() was added as a result
(between v1.2 and 1.3
http://cvs.apache.org/viewcvs/jakarta-commons/collections/src/java/org/apache/commons/collections/iterators/IteratorChain.java.diff?r1=1.2&r2=1.3&diff_format=h
as result of a bug report:
"fix bug pointed out bu Jonathan Carlson
add test that demonstrates"
So I guess fixing one bug has caused another.
BugBear
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [collections] bug in IteratorChain?
Posted by Stephen Colebourne <sc...@btopenworld.com>.
I have a vague memory of something like this getting fixed once upon a time.
Are you testing against the CVS version of this file or a release?
Stephen
----- Original Message -----
From: "Kevin O'Neill" <ke...@rocketred.com.au>
To: <co...@jakarta.apache.org>
Sent: Tuesday, December 02, 2003 12:25 AM
Subject: Re: [collections] bug in IteratorChain?
> On Mon, 01 Dec 2003 17:46:14 +0000, pwomack wrote:
>
> > The following pseudo Junit:
> >
> > Integer a = new Integer(3);
> > Integer b = new Integer(7);
> >
> > ArrayList empty = new ArrayList();
> > IteratorChain ic = new IteratorChain();
> > ic.addIterator(empty.iterator());
> > ic.addIterator(new SingletonIterator(a)); ic.addIterator(new
> > SingletonIterator(b));
> >
> > int tot = 0;
> > for(;ic.hasNext();) {
> > Integer anInt = (Integer)ic.next();
> > tot += anInt.intValue();
> > }
> > assertEquals(10, tot);
> >
> > Fails. tot is actually 0.
> >
> > I suspect the empty first Iterator somehow makes the whole iteratorChain
> > behave as if it's empty.
>
> I've encountered this myself and it was to do with the first
> iterator being empty.
>
> -k.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [collections] bug in IteratorChain?
Posted by Kevin O'Neill <ke...@rocketred.com.au>.
On Mon, 01 Dec 2003 17:46:14 +0000, pwomack wrote:
> The following pseudo Junit:
>
> Integer a = new Integer(3);
> Integer b = new Integer(7);
>
> ArrayList empty = new ArrayList();
> IteratorChain ic = new IteratorChain();
> ic.addIterator(empty.iterator());
> ic.addIterator(new SingletonIterator(a)); ic.addIterator(new
> SingletonIterator(b));
>
> int tot = 0;
> for(;ic.hasNext();) {
> Integer anInt = (Integer)ic.next();
> tot += anInt.intValue();
> }
> assertEquals(10, tot);
>
> Fails. tot is actually 0.
>
> I suspect the empty first Iterator somehow makes the whole iteratorChain
> behave as if it's empty.
I've encountered this myself and it was to do with the first
iterator being empty.
-k.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org