Groovy Quickie: AST Transformations and TypeResolver NPs
I have seen this exception every now and than, but today I write this blog post mainly to remind myself of the error cause (and share it with the reader, of course :-)).
GContracts issue #36  mentions this issue occurring on Oracle JRE 7.0 Update 10 with 1.2.9.
I located the error cause in the AST transformation that generates a class from the annotation closure expression. The code takes the Parameter instances of the current MethodNode and use them directly to create a new MethodNode.
In most cases this approach works out-of-the-box. But problems occur when generic method parameters come into play:
This caused the generated MethodNode to be equipped with a formal type parameter T, although the newly generated method itself was not generic. That has been the cause for the NullPointerException being thrown during runtime during bean introspection in java.beans.FeatureDescriptor#getParameterTypes():
If you are writing AST transformations that's definitely a dangerous trap. When reusing Parameter objects from existing MethodNode instances, one needs to be careful and create deep copied instances.