GroovyBackend needs constructor taking GroovyShell and TypeRegistry
ncadell opened this issue · comments
The GroovyBackend
has 2 constructors, one of which takes a GroovyShell
parameter. However this constructor does not support setting the TypeRegistry
. This allows creation of a GroovyBackend
with a null
TypeRegistry
, which then leads to exception when running tests.
The GroovyBackend
constructor:
public GroovyBackend(GroovyShell shell, ResourceLoader resourceLoader)
should be changed to require an additional TypeRegistry
parameter and the code for initialising the typeRegistry
and snippetGenerator
fields should be moved to this constructor.
For example:
public HybrisGroovyBackend(GroovyShell shell, ResourceLoader resourceLoader, TypeRegistry typeRegistry)
{
this.shell = shell;
this.resourceLoader = resourceLoader;
this.typeRegistry = typeRegistry;
this.snippetGenerator = new SnippetGenerator(new GroovySnippet(), typeRegistry.parameterTypeRegistry());
instanceThreadLocal.set(this);
classFinder = new ResourceLoaderClassFinder(resourceLoader, shell.getClassLoader());
}
Hi @ncadell ,
By default the constructor that is taking ResourceLoader and TypeRegistry will be called (BackendModuleBackendSupplier.java#L50)
so in groovy implementation that would be this one GroovyBackend.java#L56 which in turn is calling second constructor and initializing groovy shell, so shouldn't be a problem with initializing TypeRegistry if starting the tests via cli or e.g junit.
The only way it can cause issues if you need to initialise backend yourself, say for passing custom groovy shell. I'll add the constructor to match java implementation.
Many thanks.