Avoid NullPointerException if optional Groovy jar is removed

This commit is contained in:
Lee Hinman 2015-01-28 13:49:50 -07:00
parent c610524392
commit cc461a837f
1 changed files with 11 additions and 9 deletions

View File

@ -211,15 +211,17 @@ public class ScriptService extends AbstractComponent {
@Override @Override
public void onRefreshSettings(Settings settings) { public void onRefreshSettings(Settings settings) {
GroovyScriptEngineService engine = (GroovyScriptEngineService) ScriptService.this.scriptEngines.get("groovy"); GroovyScriptEngineService engine = (GroovyScriptEngineService) ScriptService.this.scriptEngines.get("groovy");
String[] patches = settings.getAsArray(GroovyScriptEngineService.GROOVY_SCRIPT_BLACKLIST_PATCH, Strings.EMPTY_ARRAY); if (engine != null) {
if (Arrays.equals(patches, engine.blacklistAdditions()) == false) { String[] patches = settings.getAsArray(GroovyScriptEngineService.GROOVY_SCRIPT_BLACKLIST_PATCH, Strings.EMPTY_ARRAY);
logger.info("updating [{}] from {} to {}", GroovyScriptEngineService.GROOVY_SCRIPT_BLACKLIST_PATCH, if (Arrays.equals(patches, engine.blacklistAdditions()) == false) {
engine.blacklistAdditions(), patches); logger.info("updating [{}] from {} to {}", GroovyScriptEngineService.GROOVY_SCRIPT_BLACKLIST_PATCH,
engine.blacklistAdditions(patches); engine.blacklistAdditions(), patches);
engine.reloadConfig(); engine.blacklistAdditions(patches);
// Because the GroovyScriptEngineService knows nothing about the engine.reloadConfig();
// cache, we need to clear it here if the setting changes // Because the GroovyScriptEngineService knows nothing about the
ScriptService.this.clearCache(); // cache, we need to clear it here if the setting changes
ScriptService.this.clearCache();
}
} }
} }
} }