Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-1913

Problem when running script that uses java covariants

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.0
    • 1.1-rc-1
    • groovy-jdk
    • None
    • Eclipse plugin or groovy class loader, java 5 or 6

    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)

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            vinigodoy Vinícius Godoy de Mendonça
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: