You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Andrey Artemev (JIRA)" <ji...@apache.org> on 2018/02/02 16:04:00 UTC
[jira] [Created] (GROOVY-8468) @CompileStatic runtime error when
call java implemented method that returns generic-array value
Andrey Artemev created GROOVY-8468:
--------------------------------------
Summary: @CompileStatic runtime error when call java implemented method that returns generic-array value
Key: GROOVY-8468
URL: https://issues.apache.org/jira/browse/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: AnyClass.java, AnyInterface.java, Hello.java, HelloInterface.java, test.groovy
Consider the following java classes:
Absolutly any interface:
{code:java|title=AnyInterface.java|borderStyle=solid}
public interface AnyInterface {}
{code}
Any class that implements interface :
{code:java|title=AnyClass.java|borderStyle=solid}
public class AnyClass implements AnyInterface {}
{code}
Interface with following signature (important) :
{code:java|title=HelloInterface.java|borderStyle=solid}
public interface HelloInterface {
public <T extends AnyInterface> T[] f(Class<T> clazz);
}
{code}
And the main java class where located the method that we want call from groovy ( *f* ):
{code:java|title=Hello.java|borderStyle=solid}
import java.lang.reflect.Array;
public class Hello implements HelloInterface {
@Override
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);
}
}
{code}
So if we try to call f method (Hello.java) from groovy with @CompileStatic:
{code:title=test.groovy|borderStyle=solid}
import Hello
import groovy.transform.CompileStatic
@CompileStatic
class Test {
static void test() {
Hello h = new Hello()
AnyInterface[] o = h.f(AnyClass.class)
}
}
Test.test()
{code}
we will get NoSuchMethodError :
{code}
Caught: java.lang.NoSuchMethodError: Hello.f(Ljava/lang/Class;)[Ljava/lang/Object;
java.lang.NoSuchMethodError: Hello.f(Ljava/lang/Class;)[Ljava/lang/Object;
at Test.test(test.groovy:8)
at Test$test.call(Unknown Source)
at test.run(test.groovy:12)
{code}
But without @CompileStatic annotation the code executes successfully
All sources are attached.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)