--- 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);