Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8272568

Incorrect line numbers in stack traces when using Kotlin

XMLWordPrintable

    • generic
    • generic

      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


        1. a.kt
          0.0 kB
          Andrew Wang
        2. b.kt
          0.1 kB
          Andrew Wang

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: