Andrey Artemev created GROOVY-8468:

             Summary: @CompileStatic runtime error when call java implemented 
method that returns generic-array value 
                 Key: GROOVY-8468
             Project: Groovy
          Issue Type: Bug
          Components: groovy-runtime, Static compilation
    Affects Versions: 2.4.13
         Environment: JVM 1.8.0_162,  windows 8.1
1.8.0_152-ea, 3.10.0-514.10.2.el7.x86_64 GNU/Linux
            Reporter: Andrey Artemev
         Attachments:,,,, test.groovy

Consider the following java classes:

Absolutly any interface:
public interface AnyInterface {}
Any class that implements interface :
public class AnyClass implements AnyInterface {}
Interface with following signature (important)  :
public interface HelloInterface {
    public <T extends AnyInterface> T[] f(Class<T> clazz);      
 And the main java class where located the method that we want call from groovy 
( *f* ):
import java.lang.reflect.Array;
public class Hello implements HelloInterface {
    public <T extends AnyInterface> T[] f(Class<T> clazz){
        return (T[]) Array.newInstance(clazz, 0);

    //To test f call from inside Java
    public static void main(String[] args) {
        Hello h = new Hello();
        AnyInterface[] s = h.f(AnyClass.class);

So if we try to call f method ( from groovy with @CompileStatic:
import Hello
import groovy.transform.CompileStatic

class Test {
    static void test() {
        Hello h = new Hello()
        AnyInterface[] o = h.f(AnyClass.class)


we will get NoSuchMethodError : 
Caught: java.lang.NoSuchMethodError: 
java.lang.NoSuchMethodError: Hello.f(Ljava/lang/Class;)[Ljava/lang/Object;
at Test.test(test.groovy:8)
at Test$ Source)
But without @CompileStatic annotation the code executes successfully

 All sources are attached.

This message was sent by Atlassian JIRA

Reply via email to