Skip to content

Commit

Permalink
HADOOP-10829. Iteration on CredentialProviderFactory.serviceLoader is…
Browse files Browse the repository at this point in the history
… thread-unsafe. Contributed by Benoy Antony and Rakesh R.

(cherry picked from commit b82485d)
  • Loading branch information
jnp authored and zhe-thoughts committed Jul 25, 2017
1 parent 7be52c9 commit c0e294f
Showing 1 changed file with 10 additions and 0 deletions.
Expand Up @@ -22,6 +22,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;

Expand All @@ -47,6 +48,15 @@ public abstract CredentialProvider createProvider(URI providerName,
private static final ServiceLoader<CredentialProviderFactory> serviceLoader =
ServiceLoader.load(CredentialProviderFactory.class);

// Iterate through the serviceLoader to avoid lazy loading.
// Lazy loading would require synchronization in concurrent use cases.
static {
Iterator<CredentialProviderFactory> iterServices = serviceLoader.iterator();
while (iterServices.hasNext()) {
iterServices.next();
}
}

public static List<CredentialProvider> getProviders(Configuration conf
) throws IOException {
List<CredentialProvider> result = new ArrayList<CredentialProvider>();
Expand Down

0 comments on commit c0e294f

Please sign in to comment.