I have come across a phenomenon I haven't encountered before while debugging our code.
Basically it seems like Java is skipping the last element of a collection during a for each loop.
The loop looks something like this:
for (ReportRow contentRow : rows) {
if (contentRow instanceof Data1Row) {
doSomething1();
}
if (contentRow instanceof GrossAmmountRow) {
doSomething2();
}
if (contentRow instanceof TotalAmountRow) {
doSomething3();
}
if (contentRow instanceof FinalRow) {
return null;
}
}
Now the collection "rows" consists of several elements each inheriting the parent class "ReportRow" (Data1Row, GrossAmountRow, TotalAmountRow, FinalRow).
The problem is now that the last element of the collection is getting skipped every time the loop is executed. I have already debugged the method several times to verify whether or not the collection still contains the element, but the element is present all the time - it's solely getting skipped.
My google search hasn't got me any satisfying results so I figured I would open a thread here.
Did anyone encounter something similar before? Or has an idea what could cause this problem? I am really at a loss here.
Some help would be much appreaciated!
Thank you in advance.