Occasionally, when making some updates to a Grails unit test, I will run into an error along the following lines:
BUG! exception in phase 'instruction selection' in source unit ... unexpected NullpointerException
What causes this? Or what is the best strategy to debug this problem?
My best approach thus far has been to iteratively comment things out until the code compiles. A grails clean
does not fix the issue.
Using this process I've found that the problem is my @TestFor(Class)
annotation. I had moved some code from a service to a class in src/groovy. This appears to have caused the annotation to break. I don't really understand why specifically this breaks, but that was sufficient for me to get things working.
So try removing the @TestFor()
annotation if your class under test is not a service or controller or similar.
If that doesn't work, comment everything out and add back one piece at a time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With