Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is causing "exception in phase 'instruction selection' " in Groovy / Grails unit test?

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?

like image 641
Ryan Heathcote Avatar asked Sep 21 '15 21:09

Ryan Heathcote


1 Answers

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.

like image 183
Ryan Heathcote Avatar answered Sep 21 '22 10:09

Ryan Heathcote