ppkarwasz commented on a change in pull request #804: URL: https://github.com/apache/logging-log4j2/pull/804#discussion_r831830675
########## File path: log4j-api/src/main/java/org/apache/logging/log4j/util/ServiceLoaderUtil.java ########## @@ -110,28 +135,64 @@ private ServiceLoaderUtil() { * @param logger An action to perform for each broken service. * @param services A list to add the services. */ - private static <T> void addServices(final Class<T> serviceType, final ClassLoader classLoader, - final Consumer<Throwable> logger, final Collection<T> services) { - final Iterator<T> iterator = ServiceLoader.load(serviceType, classLoader).iterator(); - while (iterator.hasNext()) { - try { - final T service = iterator.next(); - if (classLoader.equals(service.getClass().getClassLoader())) { - services.add(service); - } - } catch (ServiceConfigurationError e) { - if (logger != null) { - logger.accept(e); - } - } - } + private static <T> Stream<T> loadClassloaderServices(final Class<T> serviceType, final ClassLoader classLoader, + final boolean verbose) { + return StreamSupport.stream(new ServiceLoaderSpliterator<T>(serviceType, classLoader, verbose), false); } - private static <T> void addOsgiServices(final Class<T> serviceType, final Collection<T> services) { + private static <T> Stream<? extends T> loadOsgiServices(final Class<T> serviceType) { final Iterable<? extends T> iterable = org.glassfish.hk2.osgiresourcelocator.ServiceLoader .lookupProviderInstances(serviceType); - if (iterable != null) { - iterable.forEach(services::add); + return iterable != null ? StreamSupport.stream(iterable.spliterator(), false) : Stream.empty(); + } + + private static class ServiceLoaderSpliterator<S> implements Spliterator<S> { Review comment: I used the `stream()` method in the Java 9 specific class, so we don't forget. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org