factory should be volatile niosocketimpl-branch
authoralanb
Mon, 04 Mar 2019 08:13:31 +0000
branchniosocketimpl-branch
changeset 57240 f0e45a80ab8f
parent 57239 7636aef1b197
child 57242 c37938e150b7
factory should be volatile
src/java.base/share/classes/java/net/HttpConnectSocketImpl.java
src/java.base/share/classes/java/net/ServerSocket.java
src/java.base/share/classes/java/net/Socket.java
--- a/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java	Sat Mar 02 11:44:38 2019 +0000
+++ b/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java	Mon Mar 04 08:13:31 2019 +0000
@@ -134,7 +134,7 @@
 
         // update the Sockets impl to the impl from the http Socket
         SocketImpl si = httpSocket.impl;
-        ((SocketImpl) this).getSocket().setImpl(si);
+        getSocket().setImpl(si);
 
         // best effort is made to try and reset options previously set
         Set<Map.Entry<Integer,Object>> options = optionsMap.entrySet();
--- a/src/java.base/share/classes/java/net/ServerSocket.java	Sat Mar 02 11:44:38 2019 +0000
+++ b/src/java.base/share/classes/java/net/ServerSocket.java	Mon Mar 04 08:13:31 2019 +0000
@@ -291,6 +291,7 @@
     }
 
     private void setImpl() {
+        SocketImplFactory factory = ServerSocket.factory;
         if (factory != null) {
             impl = factory.createSocketImpl();
             checkOldImpl();
@@ -841,7 +842,7 @@
     /**
      * The factory for all server sockets.
      */
-    private static SocketImplFactory factory = null;
+    private static volatile SocketImplFactory factory;
 
     /**
      * Sets the server socket implementation factory for the
--- a/src/java.base/share/classes/java/net/Socket.java	Sat Mar 02 11:44:38 2019 +0000
+++ b/src/java.base/share/classes/java/net/Socket.java	Mon Mar 04 08:13:31 2019 +0000
@@ -161,11 +161,13 @@
             impl.setSocket(this);
         } else {
             if (p == Proxy.NO_PROXY) {
+                SocketImplFactory factory = Socket.factory;
                 if (factory == null) {
                     impl = SocketImpl.createPlatformSocketImpl(false);
-                    impl.setSocket(this);
-                } else
-                    setImpl();
+                } else {
+                    impl = factory.createSocketImpl();
+                }
+                impl.setSocket(this);
             } else
                 throw new IllegalArgumentException("Invalid Proxy");
         }
@@ -529,6 +531,7 @@
      * @since 1.4
      */
     void setImpl() {
+        SocketImplFactory factory = Socket.factory;
         if (factory != null) {
             impl = factory.createSocketImpl();
             checkOldImpl();
@@ -1731,7 +1734,7 @@
     /**
      * The factory for all client sockets.
      */
-    private static SocketImplFactory factory = null;
+    private static volatile SocketImplFactory factory;
 
     /**
      * Sets the client socket implementation factory for the