8223326: Regression introduced by CPU sync: java.security.AccessControlException: access denied ("java.net.NetPermission" "setSocketImpl")
authoraefimov
Fri, 03 May 2019 19:42:28 +0100
changeset 58614 29624901d8bc
parent 58613 eb09ad30eccb
child 58615 d5ea3bde1ebe
8223326: Regression introduced by CPU sync: java.security.AccessControlException: access denied ("java.net.NetPermission" "setSocketImpl") Reviewed-by: dfuchs, alanb Contributed-by: Alan Bateman <alan.bateman@oracle.com>
src/java.base/share/classes/sun/nio/ch/ServerSocketAdaptor.java
src/java.base/share/classes/sun/nio/ch/SocketAdaptor.java
--- a/src/java.base/share/classes/sun/nio/ch/ServerSocketAdaptor.java	Tue Apr 23 11:59:54 2019 -0700
+++ b/src/java.base/share/classes/sun/nio/ch/ServerSocketAdaptor.java	Fri May 03 19:42:28 2019 +0100
@@ -37,6 +37,9 @@
 import java.nio.channels.IllegalBlockingModeException;
 import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.SocketChannel;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Set;
 
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
@@ -59,7 +62,12 @@
     private volatile int timeout;
 
     static ServerSocket create(ServerSocketChannelImpl ssc) {
-        return new ServerSocketAdaptor(ssc);
+        PrivilegedExceptionAction<ServerSocket> pa = () -> new ServerSocketAdaptor(ssc);
+        try {
+            return AccessController.doPrivileged(pa);
+        } catch (PrivilegedActionException pae) {
+            throw new InternalError("Should not reach here", pae);
+        }
     }
 
     private ServerSocketAdaptor(ServerSocketChannelImpl ssc) {
--- a/src/java.base/share/classes/sun/nio/ch/SocketAdaptor.java	Tue Apr 23 11:59:54 2019 -0700
+++ b/src/java.base/share/classes/sun/nio/ch/SocketAdaptor.java	Fri May 03 19:42:28 2019 +0100
@@ -36,6 +36,9 @@
 import java.net.SocketOption;
 import java.net.StandardSocketOptions;
 import java.nio.channels.SocketChannel;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Set;
 
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
@@ -61,10 +64,11 @@
     }
 
     static Socket create(SocketChannelImpl sc) {
+        PrivilegedExceptionAction<Socket> pa = () -> new SocketAdaptor(sc);
         try {
-            return new SocketAdaptor(sc);
-        } catch (SocketException e) {
-            throw new InternalError("Should not reach here");
+            return AccessController.doPrivileged(pa);
+        } catch (PrivilegedActionException pae) {
+            throw new InternalError("Should not reach here", pae);
         }
     }