Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11105

Support jdk-release option for configuring the target JDK release for @CompileStatic compilations

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • Compiler
    • None

    Description

      See the motivation and description in Kotlin: https://youtrack.jetbrains.com/issue/KT-29974/Add-a-compiler-option-Xjdk-release-similar-to-javacs-release-to-control-the-target-JDK-version
       
      Sample code that requires jdk-release option for a proper compilation, and it could not be solved with "target bytecode version" alone.

      @groovy.transform.CompileStatic test() {
        def bb = java.nio.ByteBuffer.wrap(new byte[8])
        // it should compile to invokevirtual Buffer.flip()Ljava.nio.Buffer;
        // when compiling for Java 1.8 since Java 1.8 does not have ByteBuffer flip() override in ByteBuffer
        // However, if the build uses JDK17 for execution, then it contains ByteBuffer flip() override,
        // and Groovy would compile it to invokevirtual ByteBuffer.flip()Ljava.nio.ByteBuffer
        // which would fail to execute in Java 1.8
        bb.flip()
      }
      test()
      

      See https://www.morling.dev/blog/bytebuffer-and-the-dreaded-nosuchmethoderror/
      See https://stackoverflow.com/a/61267496/1261287
       

      Attachments

        Activity

          People

            Unassigned Unassigned
            vladimirsitnikov Vladimir Sitnikov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: