I finally got a chance to look at this.
The exception is being thrown because it is possible to run groovy classes in Eclipse by invoking the main method directly (this includes the implicitly generated main method). When run in this manner, ReflectionUtils.getCallingClass() is throwing the exception.
ReflectionUtils.getCallingClass() is looking up the call stack for the class of the previous interesting method call (where interesting excludes reflection and MOP methods). When run as a Groovy script, this method will return GroovyMain, but when run as a Java class, this will return null since there is no calling class when this method is invoked since it is called at the top of the call stack in the <clinit>().
I am bouncing this back to the groovy project for two reasons:
- There is nothing that I can really do about this in Eclipse
- It is possible to run compiled groovy classes using the java command and this same exception will be thrown.
The solution is to add a null check at line 211 in DefaultGroovyStaticMethods.getBundle
Currently, the code looks like:
ClassLoader targetCL = ReflectionUtils.getCallingClass().getClassLoader();
It should be:
Class c = ReflectionUtils.getCallingClass();
ClassLoader targetCL = c != null ? c.getClassLoader() : null;
Yet another situation for the elvis operator.