diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java index 05dc524260d..0210c509840 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java @@ -812,7 +812,9 @@ public class AnnotationConfiguration extends AbstractConfiguration long start = 0; if (LOG.isDebugEnabled()) start = System.nanoTime(); - List scis = ServiceLoader.load(ServletContainerInitializer.class).stream().flatMap(TypeUtil::providerMap).collect(Collectors.toList()); + List scis = ServiceLoader.load(ServletContainerInitializer.class).stream() + .flatMap(TypeUtil::providerMap) + .collect(Collectors.toList()); if (LOG.isDebugEnabled()) LOG.debug("Service loaders found in {}ms", (TimeUnit.MILLISECONDS.convert((System.nanoTime() - start), TimeUnit.NANOSECONDS))); diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/PreEncodedHttpField.java b/jetty-http/src/main/java/org/eclipse/jetty/http/PreEncodedHttpField.java index fa10c624587..36a48a82138 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/PreEncodedHttpField.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/PreEncodedHttpField.java @@ -19,9 +19,9 @@ package org.eclipse.jetty.http; import java.nio.ByteBuffer; -import java.util.ArrayList; import java.util.List; import java.util.ServiceLoader; +import java.util.stream.Collectors; import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.util.log.Log; @@ -43,11 +43,10 @@ public class PreEncodedHttpField extends HttpField static { - List encoders = new ArrayList<>(); - ServiceLoader.load(HttpFieldPreEncoder.class).stream() + List encoders = ServiceLoader.load(HttpFieldPreEncoder.class).stream() .flatMap(TypeUtil::providerMap) .filter(encoder -> index(encoder.getHttpVersion()) >= 0) - .forEach(encoders::add); + .collect(Collectors.toList()); LOG.debug("HttpField encoders loaded: {}", encoders); int size = encoders.size(); diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/SecurityHandler.java b/jetty-security/src/main/java/org/eclipse/jetty/security/SecurityHandler.java index 05fca253fbc..c1b3a84064f 100644 --- a/jetty-security/src/main/java/org/eclipse/jetty/security/SecurityHandler.java +++ b/jetty-security/src/main/java/org/eclipse/jetty/security/SecurityHandler.java @@ -78,7 +78,8 @@ public abstract class SecurityHandler extends HandlerWrapper implements Authenti static { ServiceLoader.load(Authenticator.Factory.class).stream() - .flatMap(TypeUtil::providerMap).forEach(__knownAuthenticatorFactories::add); + .flatMap(TypeUtil::providerMap) + .forEach(__knownAuthenticatorFactories::add); __knownAuthenticatorFactories.add(new DefaultAuthenticatorFactory()); } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java index 3cf57c78873..2178b56d5f7 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/TypeUtil.java @@ -760,6 +760,8 @@ public class TypeUtil * Used on a {@link ServiceLoader#stream()} with {@link Stream#flatMap(Function)}, * so that in the case a {@link ServiceConfigurationError} is thrown it warns and * continues iterating through the service loader. + *
Usage Example: + *

{@code ServiceLoader.load(Service.class).stream().flatMap(TypeUtil::providerMap).collect(Collectors.toList());}

* @param The class of the service type. * @param provider The service provider to instantiate. * @return a stream of the loaded service providers.