Fixed a possible NPE when ServiceFunctionLoader finds no OSGi service for a function.

This commit is contained in:
Ioannis Canellos 2012-08-12 21:01:13 +03:00
parent 0666a6fbde
commit 758e01a4d2
1 changed files with 5 additions and 3 deletions

View File

@ -55,13 +55,15 @@ public class ServiceFunctionLoader implements FunctionLoader {
String filter = String.format("(function=*%s.%s*)", function, ShellToken.SH.to(family)); String filter = String.format("(function=*%s.%s*)", function, ShellToken.SH.to(family));
try { try {
references = bundleContext.getServiceReferences(FunctionLoader.class.getName(), filter); references = bundleContext.getServiceReferences(FunctionLoader.class.getName(), filter);
for (ServiceReference reference : references) { if (references != null) {
for (ServiceReference reference : references) {
FunctionLoader loader = (FunctionLoader) bundleContext.getService(reference); FunctionLoader loader = (FunctionLoader) bundleContext.getService(reference);
String f = loader.loadFunction(function, family); String f = loader.loadFunction(function, family);
if (!Strings.isNullOrEmpty(f)) { if (!Strings.isNullOrEmpty(f)) {
return f; return f;
} }
} }
}
} catch (InvalidSyntaxException e) { } catch (InvalidSyntaxException e) {
throw new FunctionNotFoundException(function, family, e); throw new FunctionNotFoundException(function, family, e);
} finally { } finally {