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

Paul King updated GROOVY-8494:
------------------------------
    Description: 
Various examples still cause problems with methods on interfaces and/or JDK9.

Example 1:
{code:groovy}
import java.util.stream.Stream

class Ex1 {
    static void main(String[] args) {
        Stream.of("1").forEach{ println it }
    }
}
{code}

Example 2:
{code:groovy}
import java.util.function.Function
Function<Integer, Integer> function = Function.identity()
{code}

Example 3:
{code:groovy|title=Ex3.groovy}
public interface D {
    static D of(String s) {
        return new D() {
        };
    }
}

class C {
    static void main(String[] args) {
        D.of("1")
    }
}
{code}

2_5_X: 
The code above fails on JDK9 with:
{noformat}
java.lang.IncompatibleClassChangeError: Method 
java.util.stream.Stream.of(Ljava/lang/Object;)Ljava/util/stream/Stream; must be 
InterfaceMethodref constant
        at java_util_stream_Stream$of.call(Unknown Source)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at Ex1.main(ConsoleScript1:5)
{noformat}

With 2.4.14 on JDK8 the error is instead:
{noformat}
java.lang.VerifyError: (class: java_util_stream_Stream$of, method: callStatic 
signature: (Ljava/lang/Class;[Ljava/lang/Object;)Ljava/lang/Object;) Illegal 
type in constant pool
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
        at java.lang.Class.getConstructor0(Class.java:3075)
        at java.lang.Class.getConstructor(Class.java:1825)
        at 
org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.defineClassAndGetConstructor(ClassLoaderForClassArtifacts.java:82)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteGenerator.compileStaticMethod(CallSiteGenerator.java:262)
        at 
org.codehaus.groovy.reflection.CachedMethod.createStaticMetaMethodSite(CachedMethod.java:295)
        at 
org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.createStaticMetaMethodSite(StaticMetaMethodSite.java:114)
        at groovy.lang.MetaClassImpl.createStaticSite(MetaClassImpl.java:3421)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:76)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:161)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
        at C.main(ConsoleScript2:5)
{noformat}
And with 2.4.14 on JDK9 the error is:
{noformat}
java.lang.VerifyError: (class: java_util_stream_Stream$of, method: call 
signature: (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;) Illegal 
type in constant pool
        at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
        at 
java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3110)
        at java.base/java.lang.Class.getConstructor0(Class.java:3315)
        at java.base/java.lang.Class.getConstructor(Class.java:2108)
        at 
org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.defineClassAndGetConstructor(ClassLoaderForClassArtifacts.java:82)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteGenerator.compileStaticMethod(CallSiteGenerator.java:262)
        at 
org.codehaus.groovy.reflection.CachedMethod.createStaticMetaMethodSite(CachedMethod.java:295)
        at 
org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.createStaticMetaMethodSite(StaticMetaMethodSite.java:114)
        at groovy.lang.MetaClassImpl.createStaticSite(MetaClassImpl.java:3421)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:76)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:161)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
        at C.main(ConsoleScript0:5)
{noformat}

But the example seems to work fine with JDK8 for recent snapshots for 2_5_X, 
2_6_X and master.

The same occurs for other interface static methods also:
{code:java}
public interface D {
    static D of(String s) {
        return new D() {
        };
    }
}

class C {
    static void main(String[] args) {
        D.of("1")
    }
}
{code}
Also fails with:
 Exception in thread "main" java.lang.IncompatibleClassChangeError: Method 
test.D.of(Ljava/lang/String;)Ltest/D; must be InterfaceMethodref constant
 at test.D$of.call(Unknown Source)
 at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
 at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
 at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
 at test.C.main(C.groovy:7)

Running with JDK 8 works fine.

  was:
Trying to call Stream.of from groovy class (groovy version 2.4.12) using JDK 9 
(jdk 9 181) fails. 
Example:

{code}
package test

import java.util.stream.Stream

class B {
    static void main(String[] args) {
        Stream.of("1").forEach({ println(it) })
    }
}
{code}

The code above fails with:
Exception in thread "main" java.lang.IncompatibleClassChangeError: Method 
java.util.stream.Stream.of(Ljava/lang/Object;)Ljava/util/stream/Stream; must be 
InterfaceMethodref constant
        at java_util_stream_Stream$of.call(Unknown Source)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at test.B.main(B.groovy:7)


The same occurs for other interface static methods also:
{code}
public interface D {
    static D of(String s) {
        return new D() {
        };
    }
}

class C {
    static void main(String[] args) {
        D.of("1")
    }
}
{code}

Also fails with:
Exception in thread "main" java.lang.IncompatibleClassChangeError: Method 
test.D.of(Ljava/lang/String;)Ltest/D; must be InterfaceMethodref constant
        at test.D$of.call(Unknown Source)
        at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
        at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at test.C.main(C.groovy:7)

Running with JDK 8 works fine.


> CLONE - Calling Stream.of from groovy class in JDK 9 fails
> ----------------------------------------------------------
>
>                 Key: GROOVY-8494
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8494
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.4.12, 2.4.13, 2.4.14
>            Reporter: Marcus Nylander
>            Priority: Major
>
> Various examples still cause problems with methods on interfaces and/or JDK9.
> Example 1:
> {code:groovy}
> import java.util.stream.Stream
> class Ex1 {
>     static void main(String[] args) {
>         Stream.of("1").forEach{ println it }
>     }
> }
> {code}
> Example 2:
> {code:groovy}
> import java.util.function.Function
> Function<Integer, Integer> function = Function.identity()
> {code}
> Example 3:
> {code:groovy|title=Ex3.groovy}
> public interface D {
>     static D of(String s) {
>         return new D() {
>         };
>     }
> }
> class C {
>     static void main(String[] args) {
>         D.of("1")
>     }
> }
> {code}
> 2_5_X: 
> The code above fails on JDK9 with:
> {noformat}
> java.lang.IncompatibleClassChangeError: Method 
> java.util.stream.Stream.of(Ljava/lang/Object;)Ljava/util/stream/Stream; must 
> be InterfaceMethodref constant
>       at java_util_stream_Stream$of.call(Unknown Source)
>       at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
>       at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
>       at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
>       at Ex1.main(ConsoleScript1:5)
> {noformat}
> With 2.4.14 on JDK8 the error is instead:
> {noformat}
> java.lang.VerifyError: (class: java_util_stream_Stream$of, method: callStatic 
> signature: (Ljava/lang/Class;[Ljava/lang/Object;)Ljava/lang/Object;) Illegal 
> type in constant pool
>       at java.lang.Class.getDeclaredConstructors0(Native Method)
>       at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
>       at java.lang.Class.getConstructor0(Class.java:3075)
>       at java.lang.Class.getConstructor(Class.java:1825)
>       at 
> org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.defineClassAndGetConstructor(ClassLoaderForClassArtifacts.java:82)
>       at 
> org.codehaus.groovy.runtime.callsite.CallSiteGenerator.compileStaticMethod(CallSiteGenerator.java:262)
>       at 
> org.codehaus.groovy.reflection.CachedMethod.createStaticMetaMethodSite(CachedMethod.java:295)
>       at 
> org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.createStaticMetaMethodSite(StaticMetaMethodSite.java:114)
>       at groovy.lang.MetaClassImpl.createStaticSite(MetaClassImpl.java:3421)
>       at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:76)
>       at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:161)
>       at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
>       at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
>       at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
>       at C.main(ConsoleScript2:5)
> {noformat}
> And with 2.4.14 on JDK9 the error is:
> {noformat}
> java.lang.VerifyError: (class: java_util_stream_Stream$of, method: call 
> signature: (Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;) Illegal 
> type in constant pool
>       at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
>       at 
> java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3110)
>       at java.base/java.lang.Class.getConstructor0(Class.java:3315)
>       at java.base/java.lang.Class.getConstructor(Class.java:2108)
>       at 
> org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.defineClassAndGetConstructor(ClassLoaderForClassArtifacts.java:82)
>       at 
> org.codehaus.groovy.runtime.callsite.CallSiteGenerator.compileStaticMethod(CallSiteGenerator.java:262)
>       at 
> org.codehaus.groovy.reflection.CachedMethod.createStaticMetaMethodSite(CachedMethod.java:295)
>       at 
> org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.createStaticMetaMethodSite(StaticMetaMethodSite.java:114)
>       at groovy.lang.MetaClassImpl.createStaticSite(MetaClassImpl.java:3421)
>       at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:76)
>       at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:161)
>       at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
>       at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
>       at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
>       at C.main(ConsoleScript0:5)
> {noformat}
> But the example seems to work fine with JDK8 for recent snapshots for 2_5_X, 
> 2_6_X and master.
> The same occurs for other interface static methods also:
> {code:java}
> public interface D {
>     static D of(String s) {
>         return new D() {
>         };
>     }
> }
> class C {
>     static void main(String[] args) {
>         D.of("1")
>     }
> }
> {code}
> Also fails with:
>  Exception in thread "main" java.lang.IncompatibleClassChangeError: Method 
> test.D.of(Ljava/lang/String;)Ltest/D; must be InterfaceMethodref constant
>  at test.D$of.call(Unknown Source)
>  at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
>  at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
>  at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
>  at test.C.main(C.groovy:7)
> Running with JDK 8 works fine.



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

Reply via email to