Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.6-beta-2
-
Fix Version/s: 1.6-rc-1, 1.5.8, 1.7-beta-1
-
Component/s: None
-
Labels:None
-
Environment:Win XP SP2, JRE 1.6.0
-
Number of attachments :
Description
Open groovyConsole, enter:
class Foo {
@Delegate Date d = new Date();
}
Press Ctrl+Enter. Error displayed:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Script14: -1: Repetitive method name/signature for method 'int compareTo(java.lang.Object)' in class 'Foo'.
@ line -1, column -1.Script14: -1: Repetitive method name/signature for method 'int compareTo(java.lang.Object)' in class 'Foo'.
@ line -1, column -1.
2 errors
Note: changing Date to other classes such as Map works fine, seems to be something specific about Date.
Hi,
Please find attached the fix patches for the issue for versions 1.6-RC-1 and 1.7-beta-1.
The error was found in co-variant algorithm in Verifier.
The compilation error reported in the bug was originating from ClassCompletionVerifier->checkRepetitiveMethod() because it was seeing duplicate methods nodes for "int compareTo(Object)" added on ClassNode [Foo].
1) First method node is added by DelegateASTTransformation.addDelegateMethod() because java.util.Date class has "int compareTo(Object) [synthetic = true]"
2) Second method node is added by Verifier.addCovariantMethods().
In case of "java.util.Date implements java.lang.Comparable<Date>", what happens is that bridge method that groovy Verifier tries to add is already added by Java and java.util.Date class has following 2 methods:
1) public int compareTo(Date) [synthetic = false]
2) public int compareTo(Object) [synthetic = true] (Since this bridge method is already provided by Java, it does not need to be provided by Groovy and that is the fix done on co-variant algorithm.)
Co-variant algorithm implemented in org.codehaus.groovy.classgen.Verifier had the following issue:
, it comes across interface method "int compareTo(Object)" and method "int compareTo(Date)" on ClassNode[Foo] (added earlier by DelegateASTTransformation.addDelegateMethod()) and it incorrectly concludes that it needs to provide a bridge method "int compareTo(Object)" ignoring the possibility that it may already be present on ClassNode (as in case of java.util.Date).
To fix this, I have added an additional check in Verifier.storeMissingCovariantMethods() before adding the bridge method to ClassNode. The check is done only after co-variant case is identified by Groovy and a bridgeMethod is prepared by it so that performance hit incurred by this additional check is not added to non-co-variant cases.
With the patch, the following goes through:
class Foo { @Delegate Date d = new Date(); } def foo = new Foo() def d1 = new Date(); d1++ println foo.compareTo(d1)Hope it helps.
Roshan