Stacktrace points to line after end of file?


I get in my program an unexpected ConcurrentModificationException. The stacktrace for this exception, points to line 258 of the file - but the file has only 257 lines!

I have recompiled the file with same result.

The error happens inside a forEach{} loop, and inside that loop are some calls to inline functions that I didn’t use before: checkNotNull().

Could this somehow upset the line count?? The previous line in the stacktrace is exactly where it should be, calling the function named in the stacktrace with line 258, and below the function giving the error there are 3 other functions in the file.

The exception could be caused by calling Hibernate inside the loop, what I’m really puzzled by however is the odd line number.

Caused by: java.util.ConcurrentModificationException: null
	at java.util.ArrayList$Itr.checkForComodification( ~[na:1.8.0_131]
	at java.util.ArrayList$ ~[na:1.8.0_131]
	at org.hibernate.collection.internal.AbstractPersistentCollection$ ~[hibernate-core-5.2.10.Final.jar:5.2.10.Final]
	at nl.l1nda.jobmp.marketplace.service.impl.DefaultShiftApplicantService.checkShiftApplicants(DefaultShiftApplicantService.kt:258) ~[classes/:na]
	at nl.l1nda.jobmp.marketplace.service.impl.DefaultShiftApplicantService.addShiftApplicant(DefaultShiftApplicantService.kt:200) ~[classes/:na]

Reading deobfuscated stack trace reports in Play console

This means that the actual source line is an inlined code fragment from somewhere else. As class files (in the proper debug information) only support specifying a single source file kotlin had to use a workaround. Basically it adds a table in the class file with mappings between line number ranges and source files. The line numbers used for this are outside the actual range of line numbers of the file. The debugger/ide will “fix” it up for you, but exceptions don’t do that.


OK, thanks. It probably happened in the forEach expansion.