More cleanup. Also fix up jshell tests that depend on exception messages niosocketimpl-branch
authoralanb
Mon, 11 Feb 2019 08:39:50 +0000
branchniosocketimpl-branch
changeset 57175 7eb6cdd1204a
parent 57174 899641440751
child 57176 726630bc6a4c
More cleanup. Also fix up jshell tests that depend on exception messages
src/java.base/share/classes/java/net/DelegatingSocketImpl.java
src/java.base/share/classes/java/net/ServerSocket.java
test/langtools/jdk/jshell/JdiFailingLaunchExecutionControlTest.java
test/langtools/jdk/jshell/JdiHangingListenExecutionControlTest.java
--- a/src/java.base/share/classes/java/net/DelegatingSocketImpl.java	Sun Feb 10 19:51:43 2019 +0000
+++ b/src/java.base/share/classes/java/net/DelegatingSocketImpl.java	Mon Feb 11 08:39:50 2019 +0000
@@ -31,6 +31,8 @@
 import java.util.Objects;
 import java.util.Set;
 
+import sun.net.TrustedSocketImpl;
+
 /**
  * A SocketImpl that delegates all methods to another SocketImpl.
  */
@@ -39,6 +41,7 @@
     protected final SocketImpl delegate;
 
     DelegatingSocketImpl(SocketImpl delegate) {
+        assert delegate instanceof TrustedSocketImpl;
         this.delegate = Objects.requireNonNull(delegate);
     }
 
--- a/src/java.base/share/classes/java/net/ServerSocket.java	Sun Feb 10 19:51:43 2019 +0000
+++ b/src/java.base/share/classes/java/net/ServerSocket.java	Mon Feb 11 08:39:50 2019 +0000
@@ -566,8 +566,11 @@
             return;
         }
 
-        if (si instanceof DelegatingSocketImpl)
+        // Socket has a SOCKS or HTTP SocketImpl
+        if (si instanceof DelegatingSocketImpl) {
             si = ((DelegatingSocketImpl) si).delegate();
+            assert si instanceof TrustedSocketImpl;
+        }
 
         // ServerSocket or Socket is using a trusted SocketImpl
         if (impl instanceof TrustedSocketImpl || si instanceof TrustedSocketImpl) {
@@ -576,7 +579,14 @@
                     ? ((TrustedSocketImpl) impl).newInstance(false)
                     : ((TrustedSocketImpl) si).newInstance(false);
             impl.accept(nsi);
-            securityCheckAccept(nsi);  // closes nsi if permission check fails
+            try {
+                // a custom impl has accepted the connection with a trusted SocketImpl
+                if (!(impl instanceof TrustedSocketImpl)) {
+                    nsi.postCustomAccept();
+                }
+            } finally {
+                securityCheckAccept(nsi);  // closes nsi if permission check fails
+            }
 
             // copy state to the existing SocketImpl and update socket state
             nsi.copyTo(si);
--- a/test/langtools/jdk/jshell/JdiFailingLaunchExecutionControlTest.java	Sun Feb 10 19:51:43 2019 +0000
+++ b/test/langtools/jdk/jshell/JdiFailingLaunchExecutionControlTest.java	Mon Feb 11 08:39:50 2019 +0000
@@ -38,7 +38,7 @@
 public class JdiFailingLaunchExecutionControlTest {
 
     private static final String EXPECTED_ERROR =
-            "Launching JShell execution engine threw: Accept timed out";
+            "Launching JShell execution engine threw: accept timeout";
 
     public void failLaunchTest() {
         try {
--- a/test/langtools/jdk/jshell/JdiHangingListenExecutionControlTest.java	Sun Feb 10 19:51:43 2019 +0000
+++ b/test/langtools/jdk/jshell/JdiHangingListenExecutionControlTest.java	Mon Feb 11 08:39:50 2019 +0000
@@ -39,7 +39,7 @@
 public class JdiHangingListenExecutionControlTest {
 
     private static final String EXPECTED_ERROR =
-            "Launching JShell execution engine threw: Accept timed out";
+            "Launching JShell execution engine threw: accept timeout";
 
     public void hangListenTimeoutTest() {
         try {