Github user srdo commented on the issue:
https://github.com/apache/storm/pull/2438
@hmcl Thanks for elaborating.
As @HeartSaVioR mentions, there's a `hasNext` call in `waitingToEmit()`,
which is called before this loop, so I don't think it's possible that we call
`next` without calling `hasNext` first. That said, I agree that this change
makes the code easier to read, so we should make the change regardless.
Regarding `waitingToEmit.remove`, we aren't just failing to remove the last
element from the list. We end up back in this loop in the next call to
`nextTuple` if there are still unemitted records, so we're failing to remove
any element that results in a tuple getting emitted, since we skip
`waitingToEmit.remove` when `emitTupleIfNotEmitted` returns true. Since we
never read any element from `waitingToEmit` more than once, I think we should
remove elements as soon as they're read, i.e. something like
```java
while (waitingToEmit.hasNext()) {
boolean emitted = emitTupleIfNotEmitted(waitingToEmit.next());
waitingToEmit.remove();
if (emitted) {
break;
}
}
```
@HeartSaVioR We might need to keep the `hasNext` call in `waitingToEmit()`
since `waitingToEmit()` is also used to decide whether to poll for new records.
I think if we remove it the spout will poll for more tuples even if there are
still pending records in the `waitingToEmit` list.
---