AbstractMethodError raised at runtime - groovy subclass of parametrized abstract java superclass

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

AbstractMethodError raised at runtime - groovy subclass of parametrized abstract java superclass

Carlos Fernandez
using:
groovy-eclipse-compiler 2.6.0-01
groovy 1.8.4

I am working with a legacy java application built with maven using the
groovy-eclipse-compiler v2.6.0-01.  We tend to use Groovy when
enhancing the system or fixing defects.

I have run into a situation where a groovy class is extending a
parametrized abstract Java superclass.  The JVM throws a
AbstractMethodError when executing the resulting groovy subclass.  The
class file for the groovy subclass does not include a method signature
matching the generic abstract method defined in the Java superclass.

Here is a distilled example
==Source==
public abstract class GenericSuper<T extends Number> {

    public abstract T someMethod(T arg);

}

public class JavaSub extends GenericSuper<Long> {
    @Override
    public Long someMethod(Long someArg) {
        return someArg;
    }
}

class GroovySub extends GenericSuper<Long> {
    @Override
    Long someMethod(Long someArg) {
        someArg
    }
}

==Bytecode==
when running javap on the resulting GroovySub class:
Compiled from "GroovySub.groovy"
public class GroovySub extends GenericSuper implements groovy.lang.GroovyObject{

    public static transient boolean __$stMC;
    public GroovySub();
    public java.lang.Long someMethod(java.lang.Long);
    public java.lang.Object this$dist$invoke$2(java.lang.String, java.lang.Objec
t);
    public void this$dist$set$2(java.lang.String, java.lang.Object);
    public java.lang.Object this$dist$get$2(java.lang.String);
    protected groovy.lang.MetaClass $getStaticMetaClass();
    public groovy.lang.MetaClass getMetaClass();
    public void setMetaClass(groovy.lang.MetaClass);
    public java.lang.Object invokeMethod(java.lang.String, java.lang.Object);
    public java.lang.Object getProperty(java.lang.String);
    public void setProperty(java.lang.String, java.lang.Object);
    public static void __$swapInit();
    static {};
    public java.lang.Object someMethod(java.lang.Object);
    public void super$1$wait();
    public java.lang.String super$1$toString();
    public void super$1$wait(long, int);
    public void super$1$notify();
    public java.lang.Class super$1$getClass();
    public void super$1$notifyAll();
    public void super$1$finalize();
    public void super$1$wait(long);
    public boolean super$1$equals(java.lang.Object);
    public java.lang.Object super$1$clone();
    public int super$1$hashCode();
    static java.lang.Class class$(java.lang.String);

Notice that there are two signatures for someMethod().  One with an
Object and another with a Long.

when running javap on the resulting JavaSub class:
Compiled from "JavaSub.java"
public class JavaSub extends GenericSuper{
    public JavaSub();
    public java.lang.Long someMethod(java.lang.Long);
    public java.lang.Number someMethod(java.lang.Number);
}

There are also two signatures for someMethod().  However, one is for
Long and the other is for the "Generic" Number.

When the GroovySub is compiled using groovyc v1.8.2 the someMethod()
signatures are similar to the ones for JavaSub - Long & Number.  So
this problem appears to be a result of the eclipse groovy compiler.

Has anyone else run across this?

Carlos

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: AbstractMethodError raised at runtime - groovy subclass of parametrized abstract java superclass

Andrew Eisenberg
This sounds like there might be a bug.  Can you raise a jira issue for
this?  I'll try to have a look, but can't promise anything until the
new year.

http://jira.codehaus.org/browse/GRECLIPSE

On Tue, Dec 27, 2011 at 3:02 PM, Carlos Fernandez <[hidden email]> wrote:

> using:
> groovy-eclipse-compiler 2.6.0-01
> groovy 1.8.4
>
> I am working with a legacy java application built with maven using the
> groovy-eclipse-compiler v2.6.0-01.  We tend to use Groovy when
> enhancing the system or fixing defects.
>
> I have run into a situation where a groovy class is extending a
> parametrized abstract Java superclass.  The JVM throws a
> AbstractMethodError when executing the resulting groovy subclass.  The
> class file for the groovy subclass does not include a method signature
> matching the generic abstract method defined in the Java superclass.
>
> Here is a distilled example
> ==Source==
> public abstract class GenericSuper<T extends Number> {
>
>    public abstract T someMethod(T arg);
>
> }
>
> public class JavaSub extends GenericSuper<Long> {
>    @Override
>    public Long someMethod(Long someArg) {
>        return someArg;
>    }
> }
>
> class GroovySub extends GenericSuper<Long> {
>    @Override
>    Long someMethod(Long someArg) {
>        someArg
>    }
> }
>
> ==Bytecode==
> when running javap on the resulting GroovySub class:
> Compiled from "GroovySub.groovy"
> public class GroovySub extends GenericSuper implements groovy.lang.GroovyObject{
>
>    public static transient boolean __$stMC;
>    public GroovySub();
>    public java.lang.Long someMethod(java.lang.Long);
>    public java.lang.Object this$dist$invoke$2(java.lang.String, java.lang.Objec
> t);
>    public void this$dist$set$2(java.lang.String, java.lang.Object);
>    public java.lang.Object this$dist$get$2(java.lang.String);
>    protected groovy.lang.MetaClass $getStaticMetaClass();
>    public groovy.lang.MetaClass getMetaClass();
>    public void setMetaClass(groovy.lang.MetaClass);
>    public java.lang.Object invokeMethod(java.lang.String, java.lang.Object);
>    public java.lang.Object getProperty(java.lang.String);
>    public void setProperty(java.lang.String, java.lang.Object);
>    public static void __$swapInit();
>    static {};
>    public java.lang.Object someMethod(java.lang.Object);
>    public void super$1$wait();
>    public java.lang.String super$1$toString();
>    public void super$1$wait(long, int);
>    public void super$1$notify();
>    public java.lang.Class super$1$getClass();
>    public void super$1$notifyAll();
>    public void super$1$finalize();
>    public void super$1$wait(long);
>    public boolean super$1$equals(java.lang.Object);
>    public java.lang.Object super$1$clone();
>    public int super$1$hashCode();
>    static java.lang.Class class$(java.lang.String);
>
> Notice that there are two signatures for someMethod().  One with an
> Object and another with a Long.
>
> when running javap on the resulting JavaSub class:
> Compiled from "JavaSub.java"
> public class JavaSub extends GenericSuper{
>    public JavaSub();
>    public java.lang.Long someMethod(java.lang.Long);
>    public java.lang.Number someMethod(java.lang.Number);
> }
>
> There are also two signatures for someMethod().  However, one is for
> Long and the other is for the "Generic" Number.
>
> When the GroovySub is compiled using groovyc v1.8.2 the someMethod()
> signatures are similar to the ones for JavaSub - Long & Number.  So
> this problem appears to be a result of the eclipse groovy compiler.
>
> Has anyone else run across this?
>
> Carlos
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: AbstractMethodError raised at runtime - groovy subclass of parametrized abstract java superclass

Carlos Fernandez
Andrew,

I added the issue:  https://jira.codehaus.org/browse/GRECLIPSE-1306

Thanks for all of your help.

Carlos

On Tue, Dec 27, 2011 at 9:47 PM, Andrew Eisenberg <[hidden email]> wrote:

> This sounds like there might be a bug.  Can you raise a jira issue for
> this?  I'll try to have a look, but can't promise anything until the
> new year.
>
> http://jira.codehaus.org/browse/GRECLIPSE
>
> On Tue, Dec 27, 2011 at 3:02 PM, Carlos Fernandez <[hidden email]> wrote:
>> using:
>> groovy-eclipse-compiler 2.6.0-01
>> groovy 1.8.4
>>
>> I am working with a legacy java application built with maven using the
>> groovy-eclipse-compiler v2.6.0-01.  We tend to use Groovy when
>> enhancing the system or fixing defects.
>>
>> I have run into a situation where a groovy class is extending a
>> parametrized abstract Java superclass.  The JVM throws a
>> AbstractMethodError when executing the resulting groovy subclass.  The
>> class file for the groovy subclass does not include a method signature
>> matching the generic abstract method defined in the Java superclass.
>>
>> Here is a distilled example
>> ==Source==
>> public abstract class GenericSuper<T extends Number> {
>>
>>    public abstract T someMethod(T arg);
>>
>> }
>>
>> public class JavaSub extends GenericSuper<Long> {
>>    @Override
>>    public Long someMethod(Long someArg) {
>>        return someArg;
>>    }
>> }
>>
>> class GroovySub extends GenericSuper<Long> {
>>    @Override
>>    Long someMethod(Long someArg) {
>>        someArg
>>    }
>> }
>>
>> ==Bytecode==
>> when running javap on the resulting GroovySub class:
>> Compiled from "GroovySub.groovy"
>> public class GroovySub extends GenericSuper implements groovy.lang.GroovyObject{
>>
>>    public static transient boolean __$stMC;
>>    public GroovySub();
>>    public java.lang.Long someMethod(java.lang.Long);
>>    public java.lang.Object this$dist$invoke$2(java.lang.String, java.lang.Objec
>> t);
>>    public void this$dist$set$2(java.lang.String, java.lang.Object);
>>    public java.lang.Object this$dist$get$2(java.lang.String);
>>    protected groovy.lang.MetaClass $getStaticMetaClass();
>>    public groovy.lang.MetaClass getMetaClass();
>>    public void setMetaClass(groovy.lang.MetaClass);
>>    public java.lang.Object invokeMethod(java.lang.String, java.lang.Object);
>>    public java.lang.Object getProperty(java.lang.String);
>>    public void setProperty(java.lang.String, java.lang.Object);
>>    public static void __$swapInit();
>>    static {};
>>    public java.lang.Object someMethod(java.lang.Object);
>>    public void super$1$wait();
>>    public java.lang.String super$1$toString();
>>    public void super$1$wait(long, int);
>>    public void super$1$notify();
>>    public java.lang.Class super$1$getClass();
>>    public void super$1$notifyAll();
>>    public void super$1$finalize();
>>    public void super$1$wait(long);
>>    public boolean super$1$equals(java.lang.Object);
>>    public java.lang.Object super$1$clone();
>>    public int super$1$hashCode();
>>    static java.lang.Class class$(java.lang.String);
>>
>> Notice that there are two signatures for someMethod().  One with an
>> Object and another with a Long.
>>
>> when running javap on the resulting JavaSub class:
>> Compiled from "JavaSub.java"
>> public class JavaSub extends GenericSuper{
>>    public JavaSub();
>>    public java.lang.Long someMethod(java.lang.Long);
>>    public java.lang.Number someMethod(java.lang.Number);
>> }
>>
>> There are also two signatures for someMethod().  However, one is for
>> Long and the other is for the "Generic" Number.
>>
>> When the GroovySub is compiled using groovyc v1.8.2 the someMethod()
>> signatures are similar to the ones for JavaSub - Long & Number.  So
>> this problem appears to be a result of the eclipse groovy compiler.
>>
>> Has anyone else run across this?
>>
>> Carlos
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email