Issue Details (XML | Word | Printable)

Key: GROOVY-1860
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Blocker Blocker
Assignee: Jochen Theodorou
Reporter: Jeff Johnston
Votes: 1
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
groovy

Problem calling override method with different return type.

Created: 29/Apr/07 10:33 AM   Updated: 11/Oct/07 01:11 PM   Resolved: 11/Oct/07 01:11 PM
Return to search
Component/s: groovy-jdk
Affects Version/s: 1.0
Fix Version/s: 1.1-rc-1

Time Tracking:
Not Specified

Environment: Ubuntu Linux / JDK1.5 / Groovy 1.0
Issue Links:
Duplicate
 


 Description  « Hide

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.



Jochen Theodorou added a comment - 01/Jul/07 10:37 AM

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.


Sergey Bondarenko added a comment - 07/Aug/07 05:13 AM

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


Jochen Theodorou added a comment - 11/Oct/07 01:11 PM

fixed