Skip to content

Commit 69317b2

Browse files
committed
DefaultScriptService: fix null context bug
For languages created simply by wrapping an existing ScriptEngineFactory from the ScriptEngineManager, no context was ever being injected into the wrapped ScriptLanguage. The ScriptLanguage plugin type extends RichPlugin, which means every plugin instance is supposed to have a non-null context. Hence, this behavior should be considered a bug. Since the ScriptLanguageIndex is context-free, it does not know the context to inject it. So to fix this problem in the least invasive way, we simply have the ScriptService walk the whole list of available ScriptLanguages after initially populating them, injecting the context into any language for which it is still null.
1 parent eb76527 commit 69317b2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/main/java/org/scijava/script/DefaultScriptService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ private synchronized void initScriptLanguageIndex() {
351351
index.add(factory, true);
352352
}
353353

354+
// Inject the context into languages which need it: the
355+
// wrapped engine factories from the ScriptEngineManager.
356+
for (final ScriptLanguage language : index) {
357+
if (language.getContext() == null) language.setContext(getContext());
358+
}
359+
354360
scriptLanguageIndex = index;
355361
}
356362

0 commit comments

Comments
 (0)