Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.8-beta-3
-
Fix Version/s: 2.1.3, 2.2.0-beta-1
-
Component/s: groovy-jdk
-
Labels:
-
Number of attachments :
Description
The groovy.transform.EqualsAndHashCode AST transformation does not handle object graphs with cycles. See the attached junit tests.
Some of the test methods I included actually pass - I just included them for completeness. Basically, the equals method handles cycles just fine. The hashcode method does not so all the tests related to the hashcode method fail.
This is a pretty serious issue because these object structures are common with some frameworks (like orm tools)
There is now minimal support (in master and 2_1_X) to handle self-references in the generated equals(), plus the doco is updated a little to better set expectations - the annotation was never meant to cover all cases - just reduce boilerplate in the standard cases. Next up is to provide similar support in hashCode() for self-references. Then I think we could probably close this issue. I am not sure a general solution could be found for arbitrary mutually recursive data structures while still following Java conventions for the respective methods.