From a7f4d2606b3d2bd2fabfde573464857a3b4e021d Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Tue, 25 Feb 2020 19:48:17 +1100 Subject: [PATCH] Issue #4340 - always pass in ServiceLoader to ServiceLoaderUtil this prevents errors where jetty-util must declare it uses the provider class in module.info Signed-off-by: Lachlan Roberts --- .../jetty/alpn/client/ALPNClientConnectionFactory.java | 3 ++- .../jetty/alpn/server/ALPNServerConnectionFactory.java | 3 ++- .../eclipse/jetty/annotations/AnnotationConfiguration.java | 3 ++- .../java/org/eclipse/jetty/http/PreEncodedHttpField.java | 2 +- .../java/org/eclipse/jetty/security/SecurityHandler.java | 3 ++- .../main/java/org/eclipse/jetty/util/ServiceLoaderUtil.java | 6 +++--- .../java/org/eclipse/jetty/util/security/Credential.java | 3 ++- .../main/java/org/eclipse/jetty/webapp/Configurations.java | 3 ++- .../main/java/org/eclipse/jetty/xml/XmlConfiguration.java | 2 +- 9 files changed, 17 insertions(+), 11 deletions(-) diff --git a/jetty-alpn/jetty-alpn-client/src/main/java/org/eclipse/jetty/alpn/client/ALPNClientConnectionFactory.java b/jetty-alpn/jetty-alpn-client/src/main/java/org/eclipse/jetty/alpn/client/ALPNClientConnectionFactory.java index 8d7c75b74de..132814c1b97 100644 --- a/jetty-alpn/jetty-alpn-client/src/main/java/org/eclipse/jetty/alpn/client/ALPNClientConnectionFactory.java +++ b/jetty-alpn/jetty-alpn-client/src/main/java/org/eclipse/jetty/alpn/client/ALPNClientConnectionFactory.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.alpn.client; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.ServiceLoader; import java.util.concurrent.Executor; import javax.net.ssl.SSLEngine; @@ -53,7 +54,7 @@ public class ALPNClientConnectionFactory extends NegotiatingClientConnectionFact IllegalStateException failure = new IllegalStateException("No Client ALPNProcessors!"); // Use a for loop on iterator so load exceptions can be caught and ignored - for (Client processor : ServiceLoaderUtil.load(Client.class)) + for (Client processor : ServiceLoaderUtil.load(ServiceLoader.load(Client.class))) { try { diff --git a/jetty-alpn/jetty-alpn-server/src/main/java/org/eclipse/jetty/alpn/server/ALPNServerConnectionFactory.java b/jetty-alpn/jetty-alpn-server/src/main/java/org/eclipse/jetty/alpn/server/ALPNServerConnectionFactory.java index 12df1b5f9c4..63d49d2caeb 100644 --- a/jetty-alpn/jetty-alpn-server/src/main/java/org/eclipse/jetty/alpn/server/ALPNServerConnectionFactory.java +++ b/jetty-alpn/jetty-alpn-server/src/main/java/org/eclipse/jetty/alpn/server/ALPNServerConnectionFactory.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.alpn.server; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.ServiceLoader; import javax.net.ssl.SSLEngine; import org.eclipse.jetty.io.AbstractConnection; @@ -50,7 +51,7 @@ public class ALPNServerConnectionFactory extends NegotiatingServerConnectionFact IllegalStateException failure = new IllegalStateException("No Server ALPNProcessors!"); // Use a for loop on iterator so load exceptions can be caught and ignored - for (Server processor : ServiceLoaderUtil.load(Server.class)) + for (Server processor : ServiceLoaderUtil.load(ServiceLoader.load(Server.class))) { try { 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 273ecab21ed..407ac690db1 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 @@ -31,6 +31,7 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.ServiceLoader; import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; @@ -811,7 +812,7 @@ public class AnnotationConfiguration extends AbstractConfiguration long start = 0; if (LOG.isDebugEnabled()) start = System.nanoTime(); - List scis = ServiceLoaderUtil.load(ServletContainerInitializer.class); + List scis = ServiceLoaderUtil.load(ServiceLoader.load(ServletContainerInitializer.class)); 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 f61a615334c..9236d3468dd 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 @@ -44,7 +44,7 @@ public class PreEncodedHttpField extends HttpField static { List encoders = new ArrayList<>(); - List discoveredEncoders = ServiceLoaderUtil.load(HttpFieldPreEncoder.class); + List discoveredEncoders = ServiceLoaderUtil.load(ServiceLoader.load(HttpFieldPreEncoder.class)); for (HttpFieldPreEncoder encoder : discoveredEncoders) { if (index(encoder.getHttpVersion()) >= 0) 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 f5aa71449ab..dd1992868e8 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 @@ -26,6 +26,7 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.ServiceLoader; import java.util.Set; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -76,7 +77,7 @@ public abstract class SecurityHandler extends HandlerWrapper implements Authenti static { - __knownAuthenticatorFactories.addAll(ServiceLoaderUtil.load(Authenticator.Factory.class)); + __knownAuthenticatorFactories.addAll(ServiceLoaderUtil.load(ServiceLoader.load(Authenticator.Factory.class))); __knownAuthenticatorFactories.add(new DefaultAuthenticatorFactory()); } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ServiceLoaderUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ServiceLoaderUtil.java index c2d02091ff7..8edca00b74b 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/ServiceLoaderUtil.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ServiceLoaderUtil.java @@ -36,15 +36,15 @@ public class ServiceLoaderUtil * Uses the {@link ServiceLoader} to assemble the service providers into a list. * If loading a service type throws {@link ServiceConfigurationError}, * it warns and continues iterating through the service loader. - * @param service The interface or abstract class representing the service. * @param The class of the service type. + * @param serviceLoader The service loader to use. * @return a list of the loaded service providers. * @throws ServiceConfigurationError If the number of errors exceeds {@link #MAX_ERRORS} */ - public static List load(Class service) + public static List load(ServiceLoader serviceLoader) { List list = new ArrayList<>(); - Iterator iterator = ServiceLoader.load(service).iterator(); + Iterator iterator = serviceLoader.iterator(); int errors = 0; while (true) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java b/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java index 72e85def157..bcf4d202434 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java @@ -22,6 +22,7 @@ import java.io.Serializable; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.util.List; +import java.util.ServiceLoader; import org.eclipse.jetty.util.ServiceLoaderUtil; import org.eclipse.jetty.util.TypeUtil; @@ -43,7 +44,7 @@ public abstract class Credential implements Serializable { private static final long serialVersionUID = -7760551052768181572L; private static final Logger LOG = Log.getLogger(Credential.class); - private static final List CREDENTIAL_PROVIDERS = ServiceLoaderUtil.load(CredentialProvider.class); + private static final List CREDENTIAL_PROVIDERS = ServiceLoaderUtil.load(ServiceLoader.load(CredentialProvider.class)); /** * Check a credential diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java index 839d663bc36..51c36b8de18 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java @@ -30,6 +30,7 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.ServiceLoader; import java.util.Set; import java.util.stream.Collectors; @@ -74,7 +75,7 @@ public class Configurations extends AbstractList implements Dumpa { if (__known.isEmpty()) { - List configs = ServiceLoaderUtil.load(Configuration.class); + List configs = ServiceLoaderUtil.load(ServiceLoader.load(Configuration.class)); for (Configuration configuration : configs) { if (!configuration.isAvailable()) diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java index af3a799bd4a..80947c0ec69 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java @@ -96,7 +96,7 @@ public class XmlConfiguration { ArrayList.class, HashSet.class, Queue.class, List.class, Set.class, Collection.class }; - private static final List PROCESSOR_FACTORIES = ServiceLoaderUtil.load(ConfigurationProcessorFactory.class); + private static final List PROCESSOR_FACTORIES = ServiceLoaderUtil.load(ServiceLoader.load(ConfigurationProcessorFactory.class)); private static final XmlParser PARSER = initParser(); private static final Comparator EXECUTABLE_COMPARATOR = (o1, o2) -> {