From 0c4b35cdf7073c4066eacd31c3c8679d00413cf3 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Tue, 23 Jul 2013 20:10:12 -0700 Subject: Do not initialize SSLSocketFactory too early During Zygote initialization, the class may be preloaded. However we do not want the default instances of SSLSocketFactory initialized, so move those into a holder class so they are only initialized when used. (cherry picked from commit 72017834153711733905dfcf4bfe7b802062692b) Bug: 9984058 Change-Id: Iaf44987c9f33d160617025ca2acba5691be58143 --- src/org/apache/http/conn/ssl/SSLSocketFactory.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/org/apache/http/conn/ssl/SSLSocketFactory.java b/src/org/apache/http/conn/ssl/SSLSocketFactory.java index 1be6c3a..9195b4f 100644 --- a/src/org/apache/http/conn/ssl/SSLSocketFactory.java +++ b/src/org/apache/http/conn/ssl/SSLSocketFactory.java @@ -150,19 +150,26 @@ public class SSLSocketFactory implements LayeredSocketFactory { public static final X509HostnameVerifier STRICT_HOSTNAME_VERIFIER = new StrictHostnameVerifier(); - /** - * The factory using the default JVM settings for secure connections. + + /* + * Put defaults into holder class to avoid class preloading creating an + * instance of the classes referenced. */ - private static final SSLSocketFactory DEFAULT_FACTORY = new SSLSocketFactory(); - + private static class NoPreloadHolder { + /** + * The factory using the default JVM settings for secure connections. + */ + private static final SSLSocketFactory DEFAULT_FACTORY = new SSLSocketFactory(); + } + /** * Gets an singleton instance of the SSLProtocolSocketFactory. * @return a SSLProtocolSocketFactory */ public static SSLSocketFactory getSocketFactory() { - return DEFAULT_FACTORY; + return NoPreloadHolder.DEFAULT_FACTORY; } - + private final SSLContext sslcontext; private final javax.net.ssl.SSLSocketFactory socketfactory; private final HostNameResolver nameResolver; -- cgit v1.2.3