Fix NPE in auto-detection of SSH module of plugin
A NOP-ModuleCreator is introduced to make the coding more robust. Change-Id: I0adf995e13d8f95d961c5ded842b96cd1d57eb96
This commit is contained in:
@@ -65,32 +65,24 @@ class AutoRegisterModules {
|
||||
this.env = env;
|
||||
this.scanner = scanner;
|
||||
this.classLoader = classLoader;
|
||||
this.sshGen = env.hasSshModule() ? env.newSshModuleGenerator() : null;
|
||||
this.httpGen = env.hasHttpModule() ? env.newHttpModuleGenerator() : null;
|
||||
this.sshGen = env.hasSshModule() ? env.newSshModuleGenerator() : ModuleGenerator.NOP;
|
||||
this.httpGen = env.hasHttpModule() ? env.newHttpModuleGenerator() : ModuleGenerator.NOP;
|
||||
}
|
||||
|
||||
AutoRegisterModules discover() throws InvalidPluginException {
|
||||
sysSingletons = Sets.newHashSet();
|
||||
sysListen = LinkedListMultimap.create();
|
||||
|
||||
if (sshGen != null) {
|
||||
sshGen.setPluginName(pluginName);
|
||||
}
|
||||
if (httpGen != null) {
|
||||
httpGen.setPluginName(pluginName);
|
||||
}
|
||||
sshGen.setPluginName(pluginName);
|
||||
httpGen.setPluginName(pluginName);
|
||||
|
||||
scan();
|
||||
|
||||
if (!sysSingletons.isEmpty() || !sysListen.isEmpty()) {
|
||||
sysModule = makeSystemModule();
|
||||
}
|
||||
if (sshGen != null) {
|
||||
sshModule = sshGen.create();
|
||||
}
|
||||
if (httpGen != null) {
|
||||
httpModule = httpGen.create();
|
||||
}
|
||||
sshModule = sshGen.create();
|
||||
httpModule = httpGen.create();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -158,14 +150,10 @@ class AutoRegisterModules {
|
||||
}
|
||||
|
||||
if (is("org.apache.sshd.server.Command", clazz)) {
|
||||
if (sshGen != null) {
|
||||
sshGen.export(export, clazz);
|
||||
}
|
||||
sshGen.export(export, clazz);
|
||||
} else if (is("javax.servlet.http.HttpServlet", clazz)) {
|
||||
if (httpGen != null) {
|
||||
httpGen.export(export, clazz);
|
||||
listen(clazz, clazz);
|
||||
}
|
||||
httpGen.export(export, clazz);
|
||||
listen(clazz, clazz);
|
||||
} else {
|
||||
int cnt = sysListen.size();
|
||||
listen(clazz, clazz);
|
||||
|
||||
@@ -26,4 +26,27 @@ public interface ModuleGenerator {
|
||||
void listen(TypeLiteral<?> tl, Class<?> clazz);
|
||||
|
||||
Module create() throws InvalidPluginException;
|
||||
|
||||
public static final ModuleGenerator NOP = new ModuleGenerator() {
|
||||
|
||||
@Override
|
||||
public void setPluginName(String name) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listen(TypeLiteral<?> tl, Class<?> clazz) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void export(Export export, Class<?> type) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module create() throws InvalidPluginException {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user