From b82485d6fed2194bf0dc2eedfab7e226e30a7cf0 Mon Sep 17 00:00:00 2001 From: Jitendra Pandey Date: Fri, 7 Jul 2017 12:45:37 -0700 Subject: [PATCH] HADOOP-10829. Iteration on CredentialProviderFactory.serviceLoader is thread-unsafe. Contributed by Benoy Antony and Rakesh R. --- .../security/alias/CredentialProviderFactory.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/alias/CredentialProviderFactory.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/alias/CredentialProviderFactory.java index d1e3eb5437b..1b2ac41fa84 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/alias/CredentialProviderFactory.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/alias/CredentialProviderFactory.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.ServiceLoader; @@ -49,6 +50,15 @@ public abstract class CredentialProviderFactory { ServiceLoader.load(CredentialProviderFactory.class, CredentialProviderFactory.class.getClassLoader()); + // Iterate through the serviceLoader to avoid lazy loading. + // Lazy loading would require synchronization in concurrent use cases. + static { + Iterator iterServices = serviceLoader.iterator(); + while (iterServices.hasNext()) { + iterServices.next(); + } + } + public static List getProviders(Configuration conf ) throws IOException { List result = new ArrayList();