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

Problem calling override method with different return type.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 1.0
    • 1.1-rc-1
    • groovy-jdk
    • None
    • Ubuntu Linux / JDK1.5 / Groovy 1.0

    Description

      I am not able to call a method that is overridden to return a different type. Being able to return a different type is a JDK1.5 feature that I use a lot on my JMesa open source project. Because I was trying to groovy up my own source code I was able to trouble shoot it to figure out that the problem was with calling the overridden method. If I remove the overridden method then everything works because groovy does the duck typing. However, this is a valid JDK1.5 feature and I believe Groovy is trying to be JDK1.5 compliant.

      This is the abstract class that returns a Table object in the createTable() method:

      public abstract class AbstractTableFactory {
      public Table createTable(String... columnNames)

      { ComponentFactory factory = getComponentFactory(); Table table = factory.createTable(); ... return table; }

      }

      This is the concrete class that overrides the method and return a very specific Table...an HtmlTable. If I remove this method then Groovy calls the method from the abstract class and everything works. Of course I need this method....

      public class HtmlTableFactory {
      @Override
      public HtmlTable createTable(String... columnNames)

      { return (HtmlTable) super.createTable(columnNames); }

      }

      Here is my groovy code:

      def tableFactory = new HtmlTableFactory(webContext, coreContext);
      def columns = ["name.firstName", "name.lastName", "term", "career"] as String[];
      def table = tableFactory.createTable(columns);

      The error I get is this:

      java.lang.NoSuchMethodError: org.jmesa.view.AbstractTableFactory.createTable([Ljava/lang/String;)Lorg/jmesa/view/html/component/HtmlTable;
      gjdk.org.jmesa.view.html.HtmlTableFactory_GroovyReflector.invoke(Unknown Source)
      groovy.lang.MetaMethod.invoke(MetaMethod.java:115)
      org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)

      If it helps the decompiled groovy code is this:

      Class class1 = org.jmesaWeb.controller.BasicGroovyPresident.class;
      Class class2 = groovy.lang.MetaClass.class;
      Object tableFactory = ScriptBytecodeAdapter.invokeNewN(class1, org.jmesa.view.html.HtmlTableFactory.class, ((Object) (new Object[]

      {webContext, coreContext }

      )));
      Object columns = (String[]) ScriptBytecodeAdapter.asType(ScriptBytecodeAdapter.createList(new Object[]

      { "name.firstName", "name.lastName", "term", "career" }

      ), java.lang.String[].class);
      Object table = ScriptBytecodeAdapter.invokeMethodN(class1, tableFactory, "createTable", new Object[]

      { columns }

      );

      I hope this example makes sense as what I am trying to do is pretty straightforward.

      I was going to try and run a nightly build for 1.1 to see if this works in 1.1, but the nightly build link is broken, or the link points to an empty directory. I will submit a bug report for this as well.

      Attachments

        Issue Links

          Activity

            People

              blackdrag Jochen Theodorou
              jeff_johnston Jeff Johnston
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: