src/java.base/share/classes/java/net/Socket.java
changeset 54689 b28b7f631301
parent 54289 6183f835b9b6
child 55081 dd321e3596c0
child 57347 16c087c9103e
--- a/src/java.base/share/classes/java/net/Socket.java	Mon Apr 29 17:54:15 2019 -0700
+++ b/src/java.base/share/classes/java/net/Socket.java	Thu May 02 17:29:10 2019 +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);
     }
 
     /**
@@ -596,7 +553,7 @@
         if (isClosed())
             throw new SocketException("Socket is closed");
 
-        if (!oldImpl && isConnected())
+        if (isConnected())
             throw new SocketException("already connected");
 
         if (!(endpoint instanceof InetSocketAddress))
@@ -616,15 +573,7 @@
         }
         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
@@ -654,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)))
@@ -694,18 +643,6 @@
         bound = true;
     }
 
-    void setCreated() {
-        created = true;
-    }
-
-    void setBound() {
-        bound = true;
-    }
-
-    void setConnected() {
-        connected = true;
-    }
-
     /**
      * Returns the address to which the socket is connected.
      * <p>
@@ -957,6 +894,7 @@
     private static class SocketInputStream extends InputStream {
         private final Socket parent;
         private final InputStream in;
+
         SocketInputStream(Socket parent, InputStream in) {
             this.parent = parent;
             this.in = in;
@@ -975,6 +913,7 @@
         public int available() throws IOException {
             return in.available();
         }
+
         @Override
         public void close() throws IOException {
             parent.close();
@@ -1040,6 +979,7 @@
         public void write(byte b[], int off, int len) throws IOException {
             out.write(b, off, len);
         }
+
         @Override
         public void close() throws IOException {
             parent.close();
@@ -1672,8 +1612,7 @@
      * @since 1.4
      */
     public boolean isConnected() {
-        // Before 1.3 Sockets were always connected during creation
-        return connected || oldImpl;
+        return connected;
     }
 
     /**
@@ -1689,8 +1628,7 @@
      * @see #bind
      */
     public boolean isBound() {
-        // Before 1.3 Sockets were always bound during creation
-        return bound || oldImpl;
+        return bound;
     }
 
     /**