groovy

Problem when running script that uses java covariants

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.0
  • Fix Version/s: 1.1-rc-1
  • Component/s: groovy-jdk
  • Labels:
    None
  • Environment:
    Eclipse plugin or groovy class loader, java 5 or 6
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

Given the following java classes:

public abstract class Simple {
    public Simple getSimple() {
        return this;
    }
}

class NotSoSimple extends Simple {
    @Override public NotSoSimple getSimple() {
        return this;
    }
}

class Complex extends NotSoSimple {
    @Override public Complex getSimple() {
        return this;
    }
}

And the following Groovy Script:

class CovariantProblem {
  static void main(args) {
    	def complex = new Complex()
    	complex.getSimple()
  }
}

Groovy complains that there's no method getSimple() in Simple class.
The problem occurs both in Groovy Eclipse plugin and in Groovy classloader, as shown in the exception above:

Exception in thread "main" java.lang.NoSuchMethodError: Simple.getSimple()LComplex;
at gjdk.Complex_GroovyReflector.invoke(Unknown Source)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:115)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:450)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:119)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:111)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:187)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod0(ScriptBytecodeAdapter.java:211)
at CovariantProblem.main(CovariantProblem.groovy:6)

Activity

Hide
blackdrag blackdrag added a comment -

looks like the HEAD version is doing fine here... the exception is a bit irritating...

Exception in thread "main" java.lang.NoSuchMethodError: Simple.getSimple()LComplex;

that is no Groovy exception, it is a Java exception. Or to be clearer an exception from reflection. most probably the base call class was used in a wrong way, but that part changed pretty much. I guess it is fixed, but to be really sure I need your feedback. If the problem still remains, then reopen this issue please

Show
blackdrag blackdrag added a comment - looks like the HEAD version is doing fine here... the exception is a bit irritating... Exception in thread "main" java.lang.NoSuchMethodError: Simple.getSimple()LComplex; that is no Groovy exception, it is a Java exception. Or to be clearer an exception from reflection. most probably the base call class was used in a wrong way, but that part changed pretty much. I guess it is fixed, but to be really sure I need your feedback. If the problem still remains, then reopen this issue please

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: