[ https://issues.apache.org/jira/browse/GROOVY-8833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16641636#comment-16641636 ]
Paul King commented on GROOVY-8833: ----------------------------------- Well spotted. This is now fixed. > @Canonical creates invalid hashCode > ----------------------------------- > > Key: GROOVY-8833 > URL: https://issues.apache.org/jira/browse/GROOVY-8833 > Project: Groovy > Issue Type: Bug > Components: Compiler > Affects Versions: 2.5.2 > Reporter: Kenzie Togami > Priority: Critical > Fix For: 3.0.0-alpha-4, 2.5.3 > > > Applying {{@Canonical}} to a class will generate an invalid hashCode method > that throws a runtime cast exception. This does not happen if you apply the > individual annotations by themselves. > These tests can be injected into a Groovy test class to see the problem: > [https://gist.github.com/kenzierocks/fb0932756c3955a7ddbc0b710791af11] > I suspect the underlying cause is that {{@EqualsAndHashCode}} does not set > {{accessedVariable}} on its {{_result}} variable, which causes the verifier > to overwrite it with {{toString}}'s {{_result}} variable (see > {{FinalVariableAnalyzer#fixVar}}). This results in an invalid cast. I > observed this behavior while debugging the compiler. I'm not sure why this > doesn't also happen if the two annotations are applied by themselves, rather > than via {{@Canonical}}. > > I was able to fix this problem by setting {{_result}} to reference itself in > the AST, but perhaps that's not the right fix here. -- This message was sent by Atlassian JIRA (v7.6.3#76005)