JDK-8272568 : Incorrect line numbers in stack traces when using Kotlin
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 16
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2021-08-17
  • Updated: 2021-08-18
  • Resolved: 2021-08-18
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
I use Kotlin which has a feature of inline functions. If an exception is thrown and a stack trace is produced, it contains wrong references to files and their line numbers. It's very annoying to receive a stack trace from production that in most cases is enough to pinpoint the problem, only to find out that it's useless due to this issue. It's caused by the fact that JVM doesn't respect extra information provided in SourceDebugExtension, as specified in JSR 45 (https://jcp.org/en/jsr/detail?id=45).

There's an existing bug in Java bug tracker: https://bugs.openjdk.java.net/browse/JDK-4972961 however it's been stale for almost 18 years now (!). Since there's no way to upvote or comment under the existing bugs, and that bug tracker item doesn't reflect the impact and urgency of this bug nowadays where we have Kotlin as a popular alternative to Java, I decided to file a new item to revive the topic.

A corresponding issue in the Kotlin bug tracker, resolved because it's not Kotlin's responsibility to fix: https://youtrack.jetbrains.com/issue/KT-8628. The comments section contains most valuable information.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create such Kotlin files:

File a.kt:

inline fun a() {
    error("")
}

File b.kt (some empty lines at the end of file for the demonstrative purpose):

fun main() {
    a()
}

// line 5
// line 6
// line 7

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Exception in thread "main" java.lang.IllegalStateException: 
	at AKt.a(a.kt:2)
	at BKt.main(b.kt:2)
ACTUAL -
Exception in thread "main" java.lang.IllegalStateException: 
	at BKt.main(b.kt:9)
	at BKt.main(b.kt)

---------- BEGIN SOURCE ----------
This bug relates to Kotlin - not sure how to reproduce this issue using Java.
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Unknown.

FREQUENCY : always



Comments
The observations on Windows 10: JDK 16: Failed, at BKt.main(b.kt:9) This is not a bug in Java but an enhancement.
17-08-2021