Skip to content

Commit

Permalink
[jrubyscripting] Fix NPE caused by AbstractScriptFileWatcher initiali…
Browse files Browse the repository at this point in the history
…zation

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
  • Loading branch information
jimtng committed Mar 12, 2023
1 parent 38915f5 commit fd3dca8
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,16 @@ public JRubyScriptFileWatcher(final @Reference ScriptEngineManager manager,
final @Reference(target = "(" + Constants.SERVICE_PID
+ "=org.openhab.automation.jrubyscripting)") ScriptEngineFactory scriptEngineFactory,
final @Reference(target = WatchService.CONFIG_WATCHER_FILTER) WatchService watchService) {
super(watchService, manager, readyService, startLevelService, FILE_DIRECTORY, true);

// Pass `false` to parent constructor's `performInitialImport`
// and call it separately, _after_ initializing this.scriptEngineFactory
super(watchService, manager, readyService, startLevelService, FILE_DIRECTORY, true, false);

this.scriptEngineFactory = (JRubyScriptEngineFactory) scriptEngineFactory;

// We need to call this after initializing this.scriptEngineFactory
// because it's used inside getScriptType() below, which is called during the initialImport
performInitialImport();
}

@Override
Expand All @@ -66,6 +73,7 @@ protected Optional<String> getScriptType(Path scriptFilePath) {
if (scriptEngineFactory.isFileInGemHome(path) || scriptEngineFactory.isFileInLoadPath(path)) {
return Optional.empty();
}
return super.getScriptType(scriptFilePath);

return super.getScriptType(scriptFilePath).filter(type -> scriptEngineFactory.getScriptTypes().contains(type));
}
}

0 comments on commit fd3dca8

Please sign in to comment.