This is an automated email from the ASF dual-hosted git repository. mattsicker pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 2a03c3c6348698438293ad22177789d1997c2ba6 Author: Matt Sicker <[email protected]> AuthorDate: Sun Oct 30 19:51:53 2022 -0500 Catch ServiceConfigurationError in OSGi service loading Signed-off-by: Matt Sicker <[email protected]> --- .../apache/logging/log4j/util3/ServiceRegistry.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util3/ServiceRegistry.java b/log4j-api/src/main/java/org/apache/logging/log4j/util3/ServiceRegistry.java index f493c6110e..af57a6adc9 100644 --- a/log4j-api/src/main/java/org/apache/logging/log4j/util3/ServiceRegistry.java +++ b/log4j-api/src/main/java/org/apache/logging/log4j/util3/ServiceRegistry.java @@ -104,8 +104,22 @@ public class ServiceRegistry { public <S> void loadServicesFromBundle( final Class<S> serviceType, final long bundleId, final ClassLoader bundleClassLoader) { final List<S> services = new ArrayList<>(); - for (final S service : ServiceLoader.load(serviceType, bundleClassLoader)) { - services.add(service); + try { + final ServiceLoader<S> serviceLoader = ServiceLoader.load(serviceType, bundleClassLoader); + final Iterator<S> iterator = serviceLoader.iterator(); + while (iterator.hasNext()) { + try { + services.add(iterator.next()); + } catch (final ServiceConfigurationError sce) { + final String message = String.format("Unable to load %s service in bundle id %d", + serviceType.getName(), bundleId); + LowLevelLogUtil.logException(message, sce); + } + } + } catch (final ServiceConfigurationError e) { + final String message = String.format("Unable to load any %s services in bundle id %d", + serviceType.getName(), bundleId); + LowLevelLogUtil.logException(message, e); } registerBundleServices(serviceType, bundleId, services); }
