Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
2.5.2
-
None
Description
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.