This is a minimal reproducible example.
import java.lang.IllegalStateException // Line 1
object BadLauncher {
class A() {
}
inline fun A.b() {
throw IllegalStateException()
}
@JvmStatic
fun main(args:Array<String>) {
A().b()
}} // Line 16
Exceptions with:
Exception in thread “main” java.lang.IllegalStateException
at BadLauncher.main(main.kt:17)
There is no 17th line in this program. The stacktrace doesn’t seem to know where the exception came from.
It’s even weirder like this:
import java.lang.IllegalStateException // Line 1
object BadLauncher {
class A() {
}
inline fun A.b() {
throw IllegalStateException()
}
@JvmStatic
fun main(args:Array<String>) {
A().b()
}}
// I'm
// a
// little
// teapot // Line 21
Exceptions with:
Exception in thread “main” java.lang.IllegalStateException
at dev.fluffyderg.velandia.desktop.BadLauncher.main(BadLauncher.kt:22)
It seems to just point to the end of the entire file no matter if it is in run or debug mode…
This is pretty annoying as i’m making use of this feature in more complicated functions and the stack trace will not take me to where the exceptions are originating from.
One such example is implementing the non-nullable exception throwing versions of min() and max() that were talked about during the Kotlin 1.4 presentations (rather than the minOrNull() and maxOrNull() methods which were the original min() and max() functions in 1.3). These functions are inline in the standard library _Collections.kt class.