groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jędrzej Dąbrowa (JIRA) <>
Subject [jira] [Created] (GROOVY-8122) Wrong invokation target of static method
Date Wed, 15 Mar 2017 12:41:41 GMT
Jędrzej Dąbrowa created GROOVY-8122:

             Summary: Wrong invokation target of static method
                 Key: GROOVY-8122
             Project: Groovy
          Issue Type: Bug
          Components: groovy-runtime
    Affects Versions: 2.4.9
            Reporter: Jędrzej Dąbrowa

Given following set of java classes:

public interface Interface {
    class ExternalInterface implements Interface {}

    static Interface provide() {
        new Throwable().printStackTrace();
        return new ExternalInterface();

public abstract class MyInterface implements Interface {

    private static class MyInterfaceImpl extends MyInterface {}

    public static MyInterface provide() {
        return new MyInterfaceImpl();

And below Groovy code:

class Test {
    static void main(String[] args) {
        MyInterface myInterface = MyInterface.provide()

It yields following result:


Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot
cast object 'Interface$ExternalInterface@24a35978' with class 'Interface$ExternalInterface'
to class 'MyInterface'
	at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(
	at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(
	at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(
	at Test.main(Test.groovy:9)

Stacktrace during creating object of invalid type is:
at Interface.provide(
	at Interface$ Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
	at Test.main(Test.groovy:9)

To me this seems to be a bug. Or is this expected behavior?

This message was sent by Atlassian JIRA

View raw message