Github user hmcl commented on the issue:
https://github.com/apache/storm/pull/2438
Yes, you are right. Technically it is not necessary to remove the elements
from the collection. Nevertheless, this code change addresses the following,
important, issues:
1. Calling next() before hasNext() can throw NoSuchElementException
2. It is good practice remove the elements from the iterator (list) for two
reasons
a. to relief memory pressure. Otherwise, until a new poll happens, all
the tuples will remain in memory
b. It makes sense from a system internals standpoint: Once you emit the
record/tuple, it should no longer be in the waitingToEmit. Why should it be on
this list, if it has already been emitted?
3. The code has is is a much more common pattern, and hence better practice
as compared to the previous one.
The only reason I can think not to remove the elements from this list is
performance. If we feel it gives that much more throughput, we can can consider
not removing the elements. However, even if we don't remove the elements the
code should be along the lines (perhaps refactoring a bit to avoid the empty
body in the while loop)
```java
while (waitingToEmit.hasNext() &&
!emitTupleIfNotEmitted(waitingToEmit.next()));
```
---