deephacks / lmdbjni

LMDB for Java
Apache License 2.0
204 stars 28 forks source link

EntryIterator improperly implements Iterator interface #52

Closed devinrsmith closed 8 years ago

devinrsmith commented 8 years ago

An iterators hasNext method should be idempotent. IE, the following two pieces of code should be functionally equivalent:

while (it.hasNext()) {
  it.next();
}
while (it.hasNext()) {
  if (!it.hasNext()) {
    throw new IllegalStateException();
  }
  it.next();
}

EntryIterator doesn't allow hasNext to be called multiple times, and I've run into some bugs that were traced down to this issue.

krisskross commented 8 years ago

I have updated the implementation to respect the Iterator contract along with some more tests. Do you mind reviewing it?

devinrsmith commented 8 years ago

Looks very reasonable on first glance. I see it's very similar to guava's AbstractIterator. Thanks.

krisskross commented 8 years ago

Yes, I took inspiration from AbstractIterator. Thanks for reporting the issue and reviewing the fix.