--- old/src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java 2019-04-18 10:58:12.000000000 +0100 +++ new/src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java 2019-04-18 10:58:12.000000000 +0100 @@ -71,6 +71,12 @@ /* indicates a close is pending on the file descriptor */ protected boolean closePending = false; + /* true, if and only if, the socket is bound */ + volatile boolean bound; + + /* true, if and only if, the socket is connected */ + volatile boolean connected; + /* indicates connection reset state */ private volatile boolean connectionReset; @@ -105,6 +111,10 @@ return isReusePortAvailable; } + AbstractPlainSocketImpl(boolean server) { + super(server); + } + /** * Returns a set of SocketOptions supported by this impl and by this impl's * socket (Socket or ServerSocket) @@ -136,7 +146,7 @@ // only create the fd after we know we will be able to create the socket fd = new FileDescriptor(); try { - socketCreate(false); + socketCreate(false, server); SocketCleanable.register(fd); } catch (IOException ioe) { ResourceManager.afterUdpClose(); @@ -145,13 +155,9 @@ } } else { fd = new FileDescriptor(); - socketCreate(true); + socketCreate(true, server); SocketCleanable.register(fd); } - if (socket != null) - socket.setCreated(); - if (serverSocket != null) - serverSocket.setCreated(); } /** @@ -245,6 +251,8 @@ } else { doConnect(address, port, timeout); } + connected = true; + bound = true; // implicitly bound } public void setOption(int opt, Object val) throws SocketException { @@ -361,6 +369,7 @@ case IP_TOS: try { ret = socketGetOption(opt, null); + System.out.println("CHEGAR : ret: " + ret ); if (ret == -1) { // ipv6 tos return trafficClass; } else { @@ -368,6 +377,7 @@ } } catch (SocketException se) { // TODO - should make better effort to read TOS or TCLASS + System.out.println("CHEGAR : swallowing: " + se ); return trafficClass; // ipv6 tos } case SO_KEEPALIVE: @@ -393,7 +403,7 @@ synchronized void doConnect(InetAddress address, int port, int timeout) throws IOException { synchronized (fdLock) { - if (!closePending && (socket == null || !socket.isBound())) { + if (!closePending && (server || !bound)) { NetHooks.beforeTcpConnect(fd, address, port); } } @@ -407,14 +417,6 @@ throw new SocketException ("Socket closed"); } } - // If we have a ref. to the Socket, then sets the flags - // created, bound & connected to true. - // This is normally done in Socket.connect() but some - // subclasses of Socket may call impl.connect() directly! - if (socket != null) { - socket.setBound(); - socket.setConnected(); - } } finally { releaseFD(); } @@ -433,15 +435,12 @@ throws IOException { synchronized (fdLock) { - if (!closePending && (socket == null || !socket.isBound())) { - NetHooks.beforeTcpBind(fd, address, lport); - } - } - socketBind(address, lport); - if (socket != null) - socket.setBound(); - if (serverSocket != null) - serverSocket.setBound(); + if (!closePending && (server || !bound)) { + NetHooks.beforeTcpBind(fd, address, lport); + } + } + socketBind(address, lport); + bound = true; } /** @@ -461,6 +460,9 @@ acquireFD(); try { socketAccept(si); + bound = true; + connected = true; + //TODO REMOVE: try removing these lines to see it something will fail (setting of bound & connected ) } finally { releaseFD(); } @@ -727,7 +729,7 @@ socketClose0(false); } - abstract void socketCreate(boolean isServer) throws IOException; + abstract void socketCreate(boolean stream, boolean isServer) throws IOException; abstract void socketConnect(InetAddress address, int port, int timeout) throws IOException; abstract void socketBind(InetAddress address, int port) --- old/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java 2019-04-18 10:58:14.000000000 +0100 +++ new/src/java.base/share/classes/java/net/HttpConnectSocketImpl.java 2019-04-18 10:58:14.000000000 +0100 @@ -52,6 +52,7 @@ private final String server; private InetSocketAddress external_address; + private final Socket socket; private HashMap optionsMap = new HashMap<>(); static { @@ -75,7 +76,7 @@ } } - HttpConnectSocketImpl(Proxy proxy, SocketImpl delegate) { + HttpConnectSocketImpl(Proxy proxy, SocketImpl delegate, Socket socket) { super(delegate); SocketAddress a = proxy.address(); if ( !(a instanceof InetSocketAddress) ) @@ -84,6 +85,7 @@ InetSocketAddress ad = (InetSocketAddress) a; server = ad.getHostString(); port = ad.getPort(); + this.socket = socket; } @Override @@ -97,17 +99,6 @@ } @Override - void setSocket(Socket socket) { - delegate.socket = socket; - super.setSocket(socket); - } - - @Override - void setServerSocket(ServerSocket socket) { - throw new InternalError("should not get here"); - } - - @Override protected void connect(SocketAddress endpoint, int timeout) throws IOException { @@ -137,7 +128,7 @@ // update the Sockets impl to the impl from the http Socket SocketImpl si = httpSocket.impl; - getSocket().setImpl(si); + socket.setImpl(si); // TODO REMOVE: Is this ok, or delegating? // best effort is made to try and reset options previously set Set> options = optionsMap.entrySet(); --- old/src/java.base/share/classes/java/net/ServerSocket.java 2019-04-18 10:58:16.000000000 +0100 +++ new/src/java.base/share/classes/java/net/ServerSocket.java 2019-04-18 10:58:15.000000000 +0100 @@ -30,8 +30,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.nio.channels.ServerSocketChannel; -import java.security.AccessController; -import java.security.PrivilegedExceptionAction; import java.util.Set; import java.util.Collections; @@ -72,11 +70,6 @@ private SocketImpl impl; /** - * Are we using an older SocketImpl? - */ - private boolean oldImpl = false; - - /** * Creates a server socket with a user-specified {@code SocketImpl}. * * @param impl an instance of a SocketImpl to use on the ServerSocket. @@ -87,7 +80,6 @@ */ protected ServerSocket(SocketImpl impl) { this.impl = impl; - impl.setServerSocket(this); } /** @@ -270,36 +262,13 @@ return impl; } - private void checkOldImpl() { - if (impl == null) - return; - // SocketImpl.connect() is a protected method, therefore we need to use - // getDeclaredMethod, therefore we need permission to access the member - try { - AccessController.doPrivileged( - new PrivilegedExceptionAction() { - public Void run() throws NoSuchMethodException { - impl.getClass().getDeclaredMethod("connect", - SocketAddress.class, - int.class); - return null; - } - }); - } catch (java.security.PrivilegedActionException e) { - oldImpl = true; - } - } - private void setImpl() { SocketImplFactory factory = ServerSocket.factory; if (factory != null) { impl = factory.createSocketImpl(); - checkOldImpl(); } else { impl = SocketImpl.createPlatformSocketImpl(true); } - if (impl != null) - impl.setServerSocket(this); } /** @@ -368,7 +337,7 @@ public void bind(SocketAddress endpoint, int backlog) throws IOException { if (isClosed()) throw new SocketException("Socket is closed"); - if (!oldImpl && isBound()) + if (isBound()) throw new SocketException("Already bound"); if (endpoint == null) endpoint = new InetSocketAddress(0); @@ -722,8 +691,7 @@ * @since 1.4 */ public boolean isBound() { - // Before 1.3 ServerSockets were always bound during creation - return bound || oldImpl; + return bound; } /** @@ -863,14 +831,6 @@ ",localport=" + impl.getLocalPort() + "]"; } - void setBound() { - bound = true; - } - - void setCreated() { - created = true; - } - /** * The factory for all server sockets. */ --- old/src/java.base/share/classes/java/net/Socket.java 2019-04-18 10:58:17.000000000 +0100 +++ new/src/java.base/share/classes/java/net/Socket.java 2019-04-18 10:58:17.000000000 +0100 @@ -72,11 +72,6 @@ SocketImpl impl; /** - * Are we using an older SocketImpl? - */ - private boolean oldImpl = false; - - /** * Socket input/output streams */ private volatile InputStream in; @@ -158,8 +153,7 @@ // create a SOCKS or HTTP SocketImpl that delegates to a platform SocketImpl SocketImpl delegate = SocketImpl.createPlatformSocketImpl(false); impl = (type == Proxy.Type.SOCKS) ? new SocksSocketImpl(p, delegate) - : new HttpConnectSocketImpl(p, delegate); - impl.setSocket(this); + : new HttpConnectSocketImpl(p, delegate, this); } else { if (p == Proxy.NO_PROXY) { // create a platform or custom SocketImpl for the DIRECT case @@ -169,7 +163,6 @@ } else { impl = factory.createSocketImpl(); } - impl.setSocket(this); } else throw new IllegalArgumentException("Invalid Proxy"); } @@ -188,10 +181,6 @@ */ protected Socket(SocketImpl impl) throws SocketException { this.impl = impl; - if (impl != null) { - checkOldImpl(); - this.impl.setSocket(this); - } } /** @@ -486,37 +475,8 @@ } } - private void checkOldImpl() { - if (impl == null) - return; - // SocketImpl.connect() is a protected method, therefore we need to use - // getDeclaredMethod, therefore we need permission to access the member - - oldImpl = AccessController.doPrivileged - (new PrivilegedAction<>() { - public Boolean run() { - Class clazz = impl.getClass(); - while (true) { - try { - clazz.getDeclaredMethod("connect", SocketAddress.class, int.class); - return Boolean.FALSE; - } catch (NoSuchMethodException e) { - clazz = clazz.getSuperclass(); - // java.net.SocketImpl class will always have this abstract method. - // If we have not found it by now in the hierarchy then it does not - // exist, we are an old style impl. - if (clazz.equals(java.net.SocketImpl.class)) { - return Boolean.TRUE; - } - } - } - } - }); - } - void setImpl(SocketImpl si) { impl = si; - impl.setSocket(this); } /** @@ -527,14 +487,11 @@ SocketImplFactory factory = Socket.factory; if (factory != null) { impl = factory.createSocketImpl(); - checkOldImpl(); } else { // create a SOCKS SocketImpl that delegates to a platform SocketImpl SocketImpl delegate = SocketImpl.createPlatformSocketImpl(false); impl = new SocksSocketImpl(delegate); } - if (impl != null) - impl.setSocket(this); } /** @@ -595,7 +552,7 @@ if (isClosed()) throw new SocketException("Socket is closed"); - if (!oldImpl && isConnected()) + if (isConnected()) throw new SocketException("already connected"); if (!(endpoint instanceof InetSocketAddress)) @@ -615,15 +572,8 @@ } if (!created) createImpl(true); - if (!oldImpl) - impl.connect(epoint, timeout); - else if (timeout == 0) { - if (epoint.isUnresolved()) - impl.connect(addr.getHostName(), port); - else - impl.connect(addr, port); - } else - throw new UnsupportedOperationException("SocketImpl.connect(addr, timeout)"); + + impl.connect(epoint, timeout); connected = true; /* * If the socket was not bound before the connect, it is now because @@ -653,7 +603,7 @@ public void bind(SocketAddress bindpoint) throws IOException { if (isClosed()) throw new SocketException("Socket is closed"); - if (!oldImpl && isBound()) + if (isBound()) throw new SocketException("Already bound"); if (bindpoint != null && (!(bindpoint instanceof InetSocketAddress))) @@ -691,18 +641,7 @@ connected = true; created = true; bound = true; - } - - void setCreated() { - created = true; - } - - void setBound() { - bound = true; - } - - void setConnected() { - connected = true; + // TODO impl.postAccept(); set bound / connected } /** @@ -1670,8 +1609,7 @@ * @since 1.4 */ public boolean isConnected() { - // Before 1.3 Sockets were always connected during creation - return connected || oldImpl; + return connected; } /** @@ -1687,8 +1625,7 @@ * @see #bind */ public boolean isBound() { - // Before 1.3 Sockets were always bound during creation - return bound || oldImpl; + return bound; } /** --- old/src/java.base/share/classes/java/net/SocketImpl.java 2019-04-18 10:58:19.000000000 +0100 +++ new/src/java.base/share/classes/java/net/SocketImpl.java 2019-04-18 10:58:19.000000000 +0100 @@ -46,19 +46,32 @@ */ public abstract class SocketImpl implements SocketOptions { + // true if this SocketImpl for a ServerSocket. By default, this field + // will be set to true. It can only be set to false by platform impls. + /*package*/ final boolean server; + /** - * Creates an instance of platform's SocketImpl + * Creates a new SocketImpl. */ - @SuppressWarnings("unchecked") - static S createPlatformSocketImpl(boolean server) { - return (S) new PlainSocketImpl(); + public SocketImpl() { + this(true); + } + + /** + * Creates a new SocketImpl. + * @param server true if this SocketImpl for a ServerSocket + */ + /*package*/ SocketImpl(boolean server) { + this.server = server; } /** - * The actual Socket object. + * Creates an instance of platform's SocketImpl */ - Socket socket = null; - ServerSocket serverSocket = null; + @SuppressWarnings("unchecked") + static S createPlatformSocketImpl(boolean server) { + return (S) new PlainSocketImpl(server); + } /** * The file descriptor object for this socket. @@ -300,22 +313,6 @@ return localport; } - void setSocket(Socket soc) { - this.socket = soc; - } - - Socket getSocket() { - return socket; - } - - void setServerSocket(ServerSocket soc) { - this.serverSocket = soc; - } - - ServerSocket getServerSocket() { - return serverSocket; - } - /** * Returns the address and port of this socket as a {@code String}. * @@ -395,11 +392,9 @@ * @since 9 */ protected void setOption(SocketOption name, T value) throws IOException { - if (name == StandardSocketOptions.SO_KEEPALIVE && - (getSocket() != null)) { + if (name == StandardSocketOptions.SO_KEEPALIVE && !server) { setOption(SocketOptions.SO_KEEPALIVE, value); - } else if (name == StandardSocketOptions.SO_SNDBUF && - (getSocket() != null)) { + } else if (name == StandardSocketOptions.SO_SNDBUF && !server) { setOption(SocketOptions.SO_SNDBUF, value); } else if (name == StandardSocketOptions.SO_RCVBUF) { setOption(SocketOptions.SO_RCVBUF, value); @@ -408,13 +403,11 @@ } else if (name == StandardSocketOptions.SO_REUSEPORT && supportedOptions().contains(name)) { setOption(SocketOptions.SO_REUSEPORT, value); - } else if (name == StandardSocketOptions.SO_LINGER && - (getSocket() != null)) { + } else if (name == StandardSocketOptions.SO_LINGER && !server) { setOption(SocketOptions.SO_LINGER, value); } else if (name == StandardSocketOptions.IP_TOS) { setOption(SocketOptions.IP_TOS, value); - } else if (name == StandardSocketOptions.TCP_NODELAY && - (getSocket() != null)) { + } else if (name == StandardSocketOptions.TCP_NODELAY && !server) { setOption(SocketOptions.TCP_NODELAY, value); } else { throw new UnsupportedOperationException("unsupported option"); @@ -438,11 +431,9 @@ */ @SuppressWarnings("unchecked") protected T getOption(SocketOption name) throws IOException { - if (name == StandardSocketOptions.SO_KEEPALIVE && - (getSocket() != null)) { + if (name == StandardSocketOptions.SO_KEEPALIVE && !server) { return (T)getOption(SocketOptions.SO_KEEPALIVE); - } else if (name == StandardSocketOptions.SO_SNDBUF && - (getSocket() != null)) { + } else if (name == StandardSocketOptions.SO_SNDBUF && !server) { return (T)getOption(SocketOptions.SO_SNDBUF); } else if (name == StandardSocketOptions.SO_RCVBUF) { return (T)getOption(SocketOptions.SO_RCVBUF); @@ -451,13 +442,11 @@ } else if (name == StandardSocketOptions.SO_REUSEPORT && supportedOptions().contains(name)) { return (T)getOption(SocketOptions.SO_REUSEPORT); - } else if (name == StandardSocketOptions.SO_LINGER && - (getSocket() != null)) { + } else if (name == StandardSocketOptions.SO_LINGER && !server) { return (T)getOption(SocketOptions.SO_LINGER); } else if (name == StandardSocketOptions.IP_TOS) { return (T)getOption(SocketOptions.IP_TOS); - } else if (name == StandardSocketOptions.TCP_NODELAY && - (getSocket() != null)) { + } else if (name == StandardSocketOptions.TCP_NODELAY && !server) { return (T)getOption(SocketOptions.TCP_NODELAY); } else { throw new UnsupportedOperationException("unsupported option"); @@ -504,10 +493,10 @@ * @since 9 */ protected Set> supportedOptions() { - if (getSocket() != null) { - return socketOptions; - } else { + if (server) { return serverSocketOptions; + } else { + return socketOptions; } } } --- old/src/java.base/share/classes/java/net/SocketInputStream.java 2019-04-18 10:58:21.000000000 +0100 +++ new/src/java.base/share/classes/java/net/SocketInputStream.java 2019-04-18 10:58:20.000000000 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -48,7 +48,6 @@ private boolean eof; private AbstractPlainSocketImpl impl = null; private byte temp[]; - private Socket socket = null; /** * Creates a new SocketInputStream. Can only be called @@ -59,7 +58,6 @@ SocketInputStream(AbstractPlainSocketImpl impl) throws IOException { super(impl.getFileDescriptor()); this.impl = impl; - socket = impl.getSocket(); } /** @@ -236,23 +234,6 @@ return eof ? 0 : available; } - /** - * Closes the stream. - */ - private boolean closing = false; - public void close() throws IOException { - // Prevent recursion. See BugId 4484411 - if (closing) - return; - closing = true; - if (socket != null) { - if (!socket.isClosed()) - socket.close(); - } else - impl.close(); - closing = false; - } - void setEOF(boolean eof) { this.eof = eof; } --- old/src/java.base/share/classes/java/net/SocketOutputStream.java 2019-04-18 10:58:22.000000000 +0100 +++ new/src/java.base/share/classes/java/net/SocketOutputStream.java 2019-04-18 10:58:22.000000000 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -45,7 +45,6 @@ private AbstractPlainSocketImpl impl = null; private byte temp[] = new byte[1]; - private Socket socket = null; /** * Creates a new SocketOutputStream. Can only be called @@ -56,7 +55,6 @@ SocketOutputStream(AbstractPlainSocketImpl impl) throws IOException { super(impl.getFileDescriptor()); this.impl = impl; - socket = impl.getSocket(); } /** @@ -151,23 +149,6 @@ } /** - * Closes the stream. - */ - private boolean closing = false; - public void close() throws IOException { - // Prevent recursion. See BugId 4484411 - if (closing) - return; - closing = true; - if (socket != null) { - if (!socket.isClosed()) - socket.close(); - } else - impl.close(); - closing = false; - } - - /** * Overrides finalize, the fd is closed by the Socket. */ @SuppressWarnings({"deprecation", "removal"}) --- old/src/java.base/share/classes/java/net/SocksSocketImpl.java 2019-04-18 10:58:24.000000000 +0100 +++ new/src/java.base/share/classes/java/net/SocksSocketImpl.java 2019-04-18 10:58:23.000000000 +0100 @@ -256,17 +256,6 @@ connect(new InetSocketAddress(address, port), 0); } - @Override - void setSocket(Socket soc) { - delegate.socket = soc; - super.setSocket(soc); - } - - @Override - void setServerSocket(ServerSocket soc) { - throw new InternalError("should not get here"); - } - /** * Connects the Socks Socket to the specified endpoint. It will first * connect to the SOCKS proxy and negotiate the access. If the proxy --- old/src/java.base/unix/classes/java/net/PlainSocketImpl.java 2019-04-18 10:58:25.000000000 +0100 +++ new/src/java.base/unix/classes/java/net/PlainSocketImpl.java 2019-04-18 10:58:25.000000000 +0100 @@ -45,13 +45,8 @@ /** * Constructs an empty instance. */ - PlainSocketImpl() { } - - /** - * Constructs an instance with the given file descriptor. - */ - PlainSocketImpl(FileDescriptor fd) { - this.fd = fd; + PlainSocketImpl(boolean server) { + super(server); } static final ExtendedSocketOptions extendedOptions = @@ -90,7 +85,7 @@ protected Set> supportedOptions() { HashSet> options = new HashSet<>(super.supportedOptions()); - if (getServerSocket() != null) { + if (server) { options.addAll(ExtendedSocketOptions.serverSocketOptions()); } else { options.addAll(ExtendedSocketOptions.clientSocketOptions()); @@ -106,12 +101,12 @@ try { socketSetOption0(opt, b, val); } catch (SocketException se) { - if (socket == null || !socket.isConnected()) + if (server || !connected) throw se; } } - native void socketCreate(boolean isServer) throws IOException; + native void socketCreate(boolean stream, boolean isServer) throws IOException; native void socketConnect(InetAddress address, int port, int timeout) throws IOException; --- old/src/java.base/unix/native/libnet/PlainSocketImpl.c 2019-04-18 10:58:27.000000000 +0100 +++ new/src/java.base/unix/native/libnet/PlainSocketImpl.c 2019-04-18 10:58:27.000000000 +0100 @@ -43,7 +43,6 @@ jfieldID psi_localportID; jfieldID psi_timeoutID; jfieldID psi_trafficClassID; -jfieldID psi_serverSocketID; jfieldID psi_fdLockID; jfieldID psi_closePendingID; @@ -128,9 +127,6 @@ CHECK_NULL(psi_timeoutID); psi_trafficClassID = (*env)->GetFieldID(env, cls, "trafficClass", "I"); CHECK_NULL(psi_trafficClassID); - psi_serverSocketID = (*env)->GetFieldID(env, cls, "serverSocket", - "Ljava/net/ServerSocket;"); - CHECK_NULL(psi_serverSocketID); psi_fdLockID = (*env)->GetFieldID(env, cls, "fdLock", "Ljava/lang/Object;"); CHECK_NULL(psi_fdLockID); @@ -156,10 +152,10 @@ /* * Class: java_net_PlainSocketImpl * Method: socketCreate - * Signature: (Z)V */ + * Signature: (ZZ)V */ JNIEXPORT void JNICALL Java_java_net_PlainSocketImpl_socketCreate(JNIEnv *env, jobject this, - jboolean stream) { + jboolean stream, jboolean server) { jobject fdObj, ssObj; int fd; int type = (stream ? SOCK_STREAM : SOCK_DGRAM); @@ -202,8 +198,7 @@ * If this is a server socket then enable SO_REUSEADDR * automatically and set to non blocking. */ - ssObj = (*env)->GetObjectField(env, this, psi_serverSocketID); - if (ssObj != NULL) { + if (server) { int arg = 1; SET_NONBLOCKING(fd); if (NET_SetSockOpt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, --- old/test/jdk/java/net/Socket/OldSocketImpl.java 2019-04-18 10:58:31.000000000 +0100 +++ /dev/null 2019-04-18 10:58:31.000000000 +0100 @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import java.io.*; -import java.net.*; - -class OldSocketImpl extends SocketImpl { - public static void main(String[] args) throws Exception { - Socket.setSocketImplFactory(new SocketImplFactory() { - public SocketImpl createSocketImpl() { - return new OldSocketImpl(); - } - }); - Socket socket = new Socket("localhost", 23); - } - - public void setOption(int optID, Object value) throws SocketException { } - - public Object getOption(int optID) throws SocketException { - return null; - } - - protected void create(boolean stream) throws IOException { } - - protected void connect(String host, int port) throws IOException { } - - protected void connect(InetAddress address, int port) throws IOException { } - - // Not in 1.3... - // protected void connect(SocketAddress address, int timeout) throws IOException { } - - protected void bind(InetAddress host, int port) throws IOException { } - - protected void listen(int backlog) throws IOException { } - - protected void accept(SocketImpl s) throws IOException { } - - protected InputStream getInputStream() throws IOException { - return null; - } - - protected OutputStream getOutputStream() throws IOException { - return null; - } - - protected int available() throws IOException { - return 0; - } - - protected void close() throws IOException { } - - protected void sendUrgentData (int data) throws SocketException { } - -} --- old/test/jdk/java/net/Socket/OldSocketImplTestDriver.java 2019-04-18 10:58:32.000000000 +0100 +++ /dev/null 2019-04-18 10:58:32.000000000 +0100 @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import jdk.test.lib.process.ProcessTools; - -import java.nio.file.Path; -import java.nio.file.Paths; - -/** - * @test - * @bug 6449565 - * @library /test/lib - * @build jdk.test.lib.Utils - * jdk.test.lib.Asserts - * jdk.test.lib.JDKToolFinder - * jdk.test.lib.JDKToolLauncher - * jdk.test.lib.Platform - * jdk.test.lib.process.* - * @run main OldSocketImplTestDriver - * @summary Test driver for OdlSocketImpl - */ -public class OldSocketImplTestDriver { - public static void main(String[] args) throws Throwable { - Path jar = Paths.get(System.getProperty("test.src"), - "OldSocketImpl.jar"); - ProcessTools.executeTestJava("-cp", jar.toString(), "OldSocketImpl") - .outputTo(System.out) - .errorTo(System.out) - .shouldHaveExitValue(0); - } -}