From 0ff034bc933cdd8fd52ceab96f9d98890c6fe653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Wed, 20 Jul 2022 16:40:12 +0200 Subject: [PATCH] Add consistent null checks to ServiceHelper 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 https://github.com/eclipse-equinox/p2/issues/100 --- .../equinox/internal/p2/core/helpers/ServiceHelper.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/ServiceHelper.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/ServiceHelper.java index 60a6a029ef..05eaf2e148 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/ServiceHelper.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/ServiceHelper.java @@ -38,11 +38,12 @@ public static T getService(BundleContext context, Class clazz) { } public static T getService(BundleContext context, Class clazz, String filter) { + if (context == null) + return null; Collection> references; try { references = context.getServiceReferences(clazz, filter); } catch (InvalidSyntaxException e) { - // TODO Auto-generated catch block return null; } if (references.isEmpty()) @@ -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)