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:
Adrian Görler
2014-10-16 14:55:13 +02:00
parent 81a69c6d9d
commit d7494ad254
2 changed files with 32 additions and 21 deletions

View File

@@ -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);

View File

@@ -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;
}
};
}