Skip to content

Commit

Permalink
Add consistent null checks to ServiceHelper
Browse files Browse the repository at this point in the history
currently only half of the methods do a null check for the bundle
context the other simply run into a NPE. This adds the missing checks,
see also #100
  • Loading branch information
laeubi authored and mickaelistria committed Aug 5, 2022
1 parent 904e169 commit 0ff034b
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ public static <T> T getService(BundleContext context, Class<T> clazz) {
}

public static <T> T getService(BundleContext context, Class<T> clazz, String filter) {
if (context == null)
return null;
Collection<ServiceReference<T>> references;
try {
references = context.getServiceReferences(clazz, filter);
} catch (InvalidSyntaxException e) {
// TODO Auto-generated catch block
return null;
}
if (references.isEmpty())
Expand Down Expand Up @@ -74,11 +75,12 @@ public static Object getService(BundleContext context, String name) {
}

public static Object getService(BundleContext context, String name, String filter) {
if (context == null)
return null;
ServiceReference<?>[] references;
try {
references = context.getServiceReferences(name, filter);
} catch (InvalidSyntaxException e) {
// TODO Auto-generated catch block
return null;
}
if (references == null || references.length == 0)
Expand Down

0 comments on commit 0ff034b

Please sign in to comment.