You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2018/05/19 15:23:00 UTC

[jira] [Resolved] (GROOVY-8579) No bytecode level check is done before producing JDK8+ bytecodes

     [ https://issues.apache.org/jira/browse/GROOVY-8579?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King resolved GROOVY-8579.
-------------------------------
       Resolution: Fixed
         Assignee: Paul King
    Fix Version/s: 2.5.0-rc-3

I'll close this off. If we need further warning messages we can do the changes under a separate ticket.

> No bytecode level check is done before producing JDK8+ bytecodes
> ----------------------------------------------------------------
>
>                 Key: GROOVY-8579
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8579
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>             Fix For: 2.5.0-rc-3
>
>
> Create a file using a JDK8 static interface method, e.g. {{MyScript.groovy}}:
> {code:java}
> import groovy.transform.CompileStatic
> @CompileStatic
> Comparator myMethod() {
>     Map.Entry.comparingByKey()
> }
> {code}
> Compile using JDK8. On Groovy 3.0, use {{-Dgroovy.target.bytecode=1.7}} (not required for 2.5/6).
> Note from {{javap -v}} that the bytecode version is:
> {noformat}
>  major version: 51
> {noformat}
> and that an InterfaceMethodref to the {{Map.Entry}} static interface method exists:
> {noformat}
>    #48 = InterfaceMethodref #45.#47       // java/util/Map$Entry.comparingByKey:()Ljava/util/Comparator;
> {noformat}
> Now try to use that class in another script, e.g.:
> {code:java}
> println new MyScript().myMethod()
> {code}
> You will note this error:
> {noformat}
> java.lang.VerifyError: Illegal type at constant pool entry 48 in class MyScript
> Exception Details:
>   Location:
>     MyScript.myMethod()Ljava/util/Comparator; @0: invokestatic
>   Reason:
>     Constant pool index 48 is invalid
> {noformat}
> For Groovy 2.5/6 you can just run {{groovy MyScript.groovy}} to see the VerifyError, though using groovyc will let you see the generated bytecode.
> So there are two problems:
> * we should not set bytecode level to be the minimum level for the Groovy version (7 is default for 2.5/6) when producing bytecode requiring JDK8+.
> * we should probably just complain if {{groovy.target.bytecode}} is ever set below the minimum value for the particular Groovy version.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)