groovy

Problem calling override method with different return type.

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Fixed
  • Affects Version/s: 1.0
  • Fix Version/s: 1.1-rc-1
  • Component/s: groovy-jdk
  • Labels:
    None
  • Environment:
    Ubuntu Linux / JDK1.5 / Groovy 1.0
  • Number of attachments :
    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.

Issue Links

Activity

Hide
blackdrag blackdrag added a comment -

I changed the fix version to beta-3 because I want to do a big reorganization for things like these. I want to add an optional 1.5 module, a class file reader and other things. I need these things because I need additional type information to do this right.

Show
blackdrag blackdrag added a comment - I changed the fix version to beta-3 because I want to do a big reorganization for things like these. I want to add an optional 1.5 module, a class file reader and other things. I need these things because I need additional type information to do this right.
Hide
Sergey Bondarenko added a comment -

Hi guys. Do you know any workaround for this issue ?

Show
Sergey Bondarenko added a comment - Hi guys. Do you know any workaround for this issue ?
Hide
blackdrag blackdrag added a comment -

fixed

Show
blackdrag blackdrag added a comment - fixed

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: