History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GROOVY-2837
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Jochen Theodorou
Reporter: Gunnar Sletta
Votes: 1
Watchers: 3
Operations

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

CLONE -Groovy objects trying to override final methods

Created: 19/May/08 02:05 AM   Updated: 03/Sep/08 09:07 AM
Component/s: class generator, command line processing
Affects Version/s: 1.6-beta-1, 1.5.6
Fix Version/s: 1.5.7, 1.6-beta-2

Time Tracking:
Not Specified

File Attachments: 1. Text File GROOVY-2837.patch (2 kb)

Environment:
Windows XP
Groovy Version: 1.0 JVM: 1.6.0-b105
Groovy Version: 1.1-rc-2 JVM: 1.6.0-b105

Issue Links:
Supercedes
 


 Description  « Hide
Using a java framework that defines a class like this

public class FrameworkComponent {
// lots of fields
// lots of methods
public final Object getProperty(String name) { return frameworkStuff.get(name); }

// lots of other fields
// lots of other methods
}

If one tries to create a Groovy class that extends this
FrameworkComponent like the following:

class MyComponent extends FrameworkComponent { def size = 10 }

the groovy compiler raises an error saying that MyComponent
overrides final method getProperty(String name) from
FrameworkComponent.

Attached to this issue follows bug.zip containing a mockup of this
framework and a Groovy class that extends the framework class.

To reproduce the error just unzip the file, navigate to the unzipped folder
and fire:

groovyc -cp framework.jar MyComponent.groovy

it will raise the following error lines

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, MyComponent.groovy: -1: You are not allowed to overwrite the final method getProperty(java.lang.String) from class 'FrameworkComponent'.
@ line -1, column -1.
1 error



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Gunnar Sletta - 19/May/08 02:06 AM
Original task: http://jira.codehaus.org/browse/GROOVY-2326 claims this is fixed, but it is still reproducable with current stable version 1.5.6 and 1.6 beta.

Gunnar Sletta - 19/May/08 02:18 AM
Java Base Class:
public class Framework {
public final void setProperty(String name, Object value) { }
public final Object getProperty(String name) { return null; }
}

Groovy subclass
class FrameworkSubclass extends Framework { }


Paul King - 20/May/08 07:24 AM
changing fix version from a defunct value

Paul King - 29/May/08 12:05 AM
Attached patch (for 1_5_X branch) changes Verifier to not add getProperty, setProperty, etc. if they are found in a super class. This fixes the issue but doesn't try to address whether we should do something smarter, e.g. have our own fallback getProperty if the framework one fails?

Paul King - 30/May/08 08:17 AM
I accidentally commited the patch to the 1_5_X branch with another fix. If you are not happy with it, let me know and I will back it out. It would certainly be possible to make getMethod more efficient.

Paul King - 30/May/08 08:33 PM - edited
Strange but this broke 47 tests in the Grails build. I changed Verifier for the time being to just look within a class for getProperty and setProperty methods (not in super classes) before adding in the default implentations of those. This doesn't seem right to me but I haven't investigated enough to determine what the cause is. See here for furher info about the additional broken tests:

http://bamboo.ci.codehaus.org/browse/GRAILS-GROOVY15GRAILS-122


Jochen Theodorou - 03/Sep/08 09:07 AM
this should be fixed now