# HG changeset patch # User alanb # Date 1551780156 0 # Node ID c37938e150b7bea5158f73c88f8b471ce30060b5 # Parent f0e45a80ab8f19223e84fb93c7be199f8a831ddd More cleanup of implAccept diff -r f0e45a80ab8f -r c37938e150b7 src/java.base/share/classes/java/net/ServerSocket.java --- a/src/java.base/share/classes/java/net/ServerSocket.java Mon Mar 04 08:13:31 2019 +0000 +++ b/src/java.base/share/classes/java/net/ServerSocket.java Tue Mar 05 10:02:36 2019 +0000 @@ -574,18 +574,13 @@ // ServerSocket and Socket bound to custom SocketImpls s.impl = null; // break connection to impl - boolean completed = false; + si.reset(); try { + implAccept(si); + } catch (Exception e) { si.reset(); - // custom SocketImpl may expect fd/address to be created - si.fd = new FileDescriptor(); - si.address = new InetAddress(); - impl.accept(si); - securityCheckAccept(si); // closes si if permission check fails - completed = true; + throw e; } finally { - if (!completed) - si.reset(); s.impl = si; // restore connection to impl } s.postAccept(); @@ -607,6 +602,12 @@ " cannot accept a connection with an instance of " + si.getClass()); } + // custom SocketImpl may expect fd/address objects to be created + if (!(si instanceof PlatformSocketImpl)) { + si.fd = new FileDescriptor(); + si.address = new InetAddress(); + } + // accept a connection impl.accept(si); @@ -619,14 +620,7 @@ } } - securityCheckAccept(si); // closes si if permission check fails - } - - /** - * Invokes the security manager's checkAccept method. If the permission - * check fails then it closes the SocketImpl. - */ - private void securityCheckAccept(SocketImpl si) throws IOException { + // check permission, close SocketImpl/connection if denied SecurityManager sm = System.getSecurityManager(); if (sm != null) { try { diff -r f0e45a80ab8f -r c37938e150b7 src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java --- a/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java Mon Mar 04 08:13:31 2019 +0000 +++ b/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java Tue Mar 05 10:02:36 2019 +0000 @@ -151,6 +151,9 @@ * Throws SocketException if the socket is not open. */ private void ensureOpen() throws SocketException { + int state = this.state; + if (state == ST_NEW) + throw new SocketException("Socket not created"); if (state >= ST_CLOSING) throw new SocketException("Socket closed"); }