< prev index next >

src/java.base/share/classes/javax/net/ssl/SSLContext.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 24,36 **** */ package javax.net.ssl; import java.security.*; - import java.lang.invoke.MethodHandles; - import java.lang.invoke.VarHandle; import java.util.Objects; import sun.security.jca.GetInstance; /** * Instances of this class represent a secure socket protocol * implementation which acts as a factory for secure socket --- 24,35 ---- */ package javax.net.ssl; import java.security.*; import java.util.Objects; + import sun.security.jca.GetInstance; /** * Instances of this class represent a secure socket protocol * implementation which acts as a factory for secure socket
*** 57,80 **** private final SSLContextSpi contextSpi; private final String protocol; - private static volatile SSLContext defaultContext; - - private static final VarHandle VH_DEFAULT_CONTEXT; - - static { - try { - VH_DEFAULT_CONTEXT = MethodHandles.lookup() - .findStaticVarHandle( - SSLContext.class, "defaultContext", SSLContext.class); - } catch (Exception e) { - throw new ExceptionInInitializerError(e); - } - } - /** * Creates an SSLContext object. * * @param contextSpi the delegate * @param provider the provider --- 56,65 ----
*** 85,94 **** --- 70,81 ---- this.contextSpi = contextSpi; this.provider = provider; this.protocol = protocol; } + private static SSLContext defaultContext; + /** * Returns the default SSL context. * * <p>If a default context was set using the {@link #setDefault * SSLContext.setDefault()} method, it is returned. Otherwise, the first
*** 102,121 **** * @return the default SSL context * @throws NoSuchAlgorithmException if the * {@link SSLContext#getInstance SSLContext.getInstance()} call fails * @since 1.6 */ ! public static SSLContext getDefault() throws NoSuchAlgorithmException { ! SSLContext temporaryContext = defaultContext; ! if (temporaryContext == null) { ! temporaryContext = SSLContext.getInstance("Default"); ! if (!VH_DEFAULT_CONTEXT.compareAndSet(null, temporaryContext)) { ! temporaryContext = defaultContext; ! } } ! ! return temporaryContext; } /** * Sets the default SSL context. It will be returned by subsequent calls * to {@link #getDefault}. The default context must be immediately usable --- 89,104 ---- * @return the default SSL context * @throws NoSuchAlgorithmException if the * {@link SSLContext#getInstance SSLContext.getInstance()} call fails * @since 1.6 */ ! public static synchronized SSLContext getDefault() ! throws NoSuchAlgorithmException { ! if (defaultContext == null) { ! defaultContext = SSLContext.getInstance("Default"); } ! return defaultContext; } /** * Sets the default SSL context. It will be returned by subsequent calls * to {@link #getDefault}. The default context must be immediately usable
*** 126,144 **** * @throws SecurityException if a security manager exists and its * {@code checkPermission} method does not allow * {@code SSLPermission("setDefaultSSLContext")} * @since 1.6 */ ! public static void setDefault(SSLContext context) { if (context == null) { throw new NullPointerException(); } SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new SSLPermission("setDefaultSSLContext")); } - defaultContext = context; } /** * Returns a {@code SSLContext} object that implements the --- 109,126 ---- * @throws SecurityException if a security manager exists and its * {@code checkPermission} method does not allow * {@code SSLPermission("setDefaultSSLContext")} * @since 1.6 */ ! public static synchronized void setDefault(SSLContext context) { if (context == null) { throw new NullPointerException(); } SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new SSLPermission("setDefaultSSLContext")); } defaultContext = context; } /** * Returns a {@code SSLContext} object that implements the
< prev index next >