Skip to content

Commit 68f5ee2

Browse files
committed
Avoid NullPointerException if optional Groovy jar is removed
1 parent 64d8e2a commit 68f5ee2

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/main/java/org/elasticsearch/script/ScriptService.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,17 @@ class ApplySettings implements NodeSettingsService.Listener {
225225
@Override
226226
public void onRefreshSettings(Settings settings) {
227227
GroovyScriptEngineService engine = (GroovyScriptEngineService) ScriptService.this.scriptEngines.get("groovy");
228-
String[] patches = settings.getAsArray(GroovyScriptEngineService.GROOVY_SCRIPT_BLACKLIST_PATCH, Strings.EMPTY_ARRAY);
229-
if (Arrays.equals(patches, engine.blacklistAdditions()) == false) {
230-
logger.info("updating [{}] from {} to {}", GroovyScriptEngineService.GROOVY_SCRIPT_BLACKLIST_PATCH,
231-
engine.blacklistAdditions(), patches);
232-
engine.blacklistAdditions(patches);
233-
engine.reloadConfig();
234-
// Because the GroovyScriptEngineService knows nothing about the
235-
// cache, we need to clear it here if the setting changes
236-
ScriptService.this.clearCache();
228+
if (engine != null) {
229+
String[] patches = settings.getAsArray(GroovyScriptEngineService.GROOVY_SCRIPT_BLACKLIST_PATCH, Strings.EMPTY_ARRAY);
230+
if (Arrays.equals(patches, engine.blacklistAdditions()) == false) {
231+
logger.info("updating [{}] from {} to {}", GroovyScriptEngineService.GROOVY_SCRIPT_BLACKLIST_PATCH,
232+
engine.blacklistAdditions(), patches);
233+
engine.blacklistAdditions(patches);
234+
engine.reloadConfig();
235+
// Because the GroovyScriptEngineService knows nothing about the
236+
// cache, we need to clear it here if the setting changes
237+
ScriptService.this.clearCache();
238+
}
237239
}
238240
}
239241
}

0 commit comments

Comments
 (0)