0

I met with a problem that, when I use for-iterator, I changed the list(ArrayList) to which the iterator belongs:

for (Term term : terms) {
    for (int j = 0; j < expr2.getTerms().size(); j++) {
        res.add(term.mulTerm(expr2.getTerms().get(j)));
    }
}

But the IntelliJ IDEA didn't give any signals and run as normal, it just shew:

Process finished with exit code 0

But when I used single-step debugging in IntelliJ IDEA, and it could be seen that the program executed the codes below:

final void checkForComodification() {
    if (modCount != expectedModCount)
        throw new ConcurrentModificationException();
}

And finally the program stopped and returned as normal while it had thrown ConcurrentModificationException. I'm wondering why this phenomenon occurred, thank you!

NormalLLer
  • 183
  • 2
  • 11
  • 1
    Perhaps there is a global try-catch somewhere in your code, which shuts down everything on error, but does not report it? Exit code 0 normally means the process terminated normally without errors. – Chaosfire Mar 09 '22 at 11:14
  • @Chaosfire, I didn't catch any exception, That's puzzling. – NormalLLer Mar 09 '22 at 11:42
  • Your code fragment doesn't show that it modifies the list to which the iterator belongs. You are modifying `res`, but the code does not iterator over `res`. – Thomas Kläger Mar 09 '22 at 11:59
  • @ThomasKläger, I got it. So do you mean that the ```ConcurrentModificationException``` did happened, but it happened on ```res``` but not on iterator so the IDE did not report? – NormalLLer Mar 09 '22 at 12:10
  • 1
    No, I suspect that the `ConcurrentModificationException` never happens. The JVM reports thrown exceptions that are not caught. That it doesn't report it implies that it either was caught in a try - catch or that is was never thrown in the first place. (And note that the IDE has no word in this process. It just shows what the JVM prints.) – Thomas Kläger Mar 09 '22 at 12:30
  • 1
    While debugging it sometimes happens that the line numbers that you seem to step through do not match the actual line numbers in the source. So it can be that while debugging it seemed that the line `throw new ConcurrentModificationException();` was executed but what actually was executed was a line above or below that. – Thomas Kläger Mar 09 '22 at 12:32
  • @ThomasKläger, I understood, thanks so much! – NormalLLer Mar 09 '22 at 13:05

0 Answers0