am e6cfe4d5: am a6d2b916: am 89c50e8b: Delay SSLSocketImpl instantiation until needed
* commit 'e6cfe4d5d488fa66d555bfcf07d8155d684bc8d6':
Delay SSLSocketImpl instantiation until needed
diff --git a/luni/src/main/java/javax/net/ssl/HttpsURLConnection.java b/luni/src/main/java/javax/net/ssl/HttpsURLConnection.java
index 0f22f38..4112dc4 100644
--- a/luni/src/main/java/javax/net/ssl/HttpsURLConnection.java
+++ b/luni/src/main/java/javax/net/ssl/HttpsURLConnection.java
@@ -102,11 +102,16 @@
* connection will be retried with SSLv3 only.
*/
public abstract class HttpsURLConnection extends HttpURLConnection {
+ /*
+ * Holds default instances so class preloading doesn't create an instance of
+ * it.
+ */
+ private static class NoPreloadHolder {
+ public static HostnameVerifier defaultHostnameVerifier = new DefaultHostnameVerifier();
- private static HostnameVerifier defaultHostnameVerifier = new DefaultHostnameVerifier();
-
- private static SSLSocketFactory defaultSSLSocketFactory = (SSLSocketFactory) SSLSocketFactory
- .getDefault();
+ public static SSLSocketFactory defaultSSLSocketFactory = (SSLSocketFactory) SSLSocketFactory
+ .getDefault();
+ }
/**
* Sets the default hostname verifier to be used by new instances.
@@ -120,7 +125,7 @@
if (v == null) {
throw new IllegalArgumentException("HostnameVerifier is null");
}
- defaultHostnameVerifier = v;
+ NoPreloadHolder.defaultHostnameVerifier = v;
}
/**
@@ -129,7 +134,7 @@
* @return the default hostname verifier.
*/
public static HostnameVerifier getDefaultHostnameVerifier() {
- return defaultHostnameVerifier;
+ return NoPreloadHolder.defaultHostnameVerifier;
}
/**
@@ -144,7 +149,7 @@
if (sf == null) {
throw new IllegalArgumentException("SSLSocketFactory is null");
}
- defaultSSLSocketFactory = sf;
+ NoPreloadHolder.defaultSSLSocketFactory = sf;
}
/**
@@ -153,7 +158,7 @@
* @return the default SSL socket factory for new instances.
*/
public static SSLSocketFactory getDefaultSSLSocketFactory() {
- return defaultSSLSocketFactory;
+ return NoPreloadHolder.defaultSSLSocketFactory;
}
/**
@@ -174,8 +179,8 @@
*/
protected HttpsURLConnection(URL url) {
super(url);
- hostnameVerifier = defaultHostnameVerifier;
- sslSocketFactory = defaultSSLSocketFactory;
+ hostnameVerifier = NoPreloadHolder.defaultHostnameVerifier;
+ sslSocketFactory = NoPreloadHolder.defaultSSLSocketFactory;
}
/**
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java
index 4cc16e6..ed5c814 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java
@@ -717,7 +717,7 @@
} catch (IOException e) {
// return an invalid session with
// invalid cipher suite of "SSL_NULL_WITH_NULL_NULL"
- return SSLSessionImpl.NULL_SESSION;
+ return SSLSessionImpl.getNullSession();
}
}
return sslSession;
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java
index af03325..7f01c8a 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLEngineImpl.java
@@ -370,7 +370,7 @@
if (session != null) {
return session;
}
- return SSLSessionImpl.NULL_SESSION;
+ return SSLSessionImpl.getNullSession();
}
/**
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java
index 247c6ee..46834ad 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java
@@ -33,8 +33,13 @@
public final class SSLSessionImpl implements SSLSession, Cloneable {
- /** Session object reporting an invalid cipher suite of "SSL_NULL_WITH_NULL_NULL" */
- public static final SSLSessionImpl NULL_SESSION = new SSLSessionImpl(null);
+ /*
+ * Holds default instances so class preloading doesn't create an instance of
+ * it.
+ */
+ private static class DefaultHolder {
+ public static final SSLSessionImpl NULL_SESSION = new SSLSessionImpl(null);
+ }
private long creationTime;
private boolean isValid = true;
@@ -54,6 +59,10 @@
byte[] serverRandom;
final boolean isServer;
+ public static SSLSessionImpl getNullSession() {
+ return DefaultHolder.NULL_SESSION;
+ }
+
public SSLSessionImpl(CipherSuite cipher_suite, SecureRandom secureRandom) {
creationTime = System.currentTimeMillis();
lastAccessedTime = creationTime;
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketImpl.java
index 2cd2cf5..3e72aeb 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketImpl.java
@@ -391,7 +391,7 @@
} catch (IOException e) {
// return an invalid session with
// invalid cipher suite of "SSL_NULL_WITH_NULL_NULL"
- return SSLSessionImpl.NULL_SESSION;
+ return SSLSessionImpl.getNullSession();
}
}
return session;