# HG changeset patch
# User peter.gergely.horvath
# Date 1524424973 -7200
#      Sun Apr 22 21:22:53 2018 +0200
# Node ID d54fcbb0bc4ba36fb58c8b306fff55d9f188183e
# Parent  bfba4712d4ffbdb4b8c4e3551440a4f269a2f456
Socket now reports the connection details on connection failure

diff -r bfba4712d4ff -r d54fcbb0bc4b src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java
--- a/src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java	Wed Apr 18 11:36:48 2018 +0200
+++ b/src/java.base/share/classes/java/net/AbstractPlainSocketImpl.java	Sun Apr 22 21:22:53 2018 +0200
@@ -413,12 +413,42 @@
             } finally {
                 releaseFD();
             }
+        } catch (ConnectException e) {
+            close();
+            throw new ConnectException(buildConnectFailureMessage(address, port, timeout, e.getMessage()));
+
+        } catch (NoRouteToHostException e) {
+            close();
+            throw new NoRouteToHostException(buildConnectFailureMessage(address, port, timeout, e.getMessage()));
+
+        } catch (SocketException e) {
+            close();
+            throw new SocketException(buildConnectFailureMessage(address, port, timeout, e.getMessage()));
+
+        } catch (SocketTimeoutException e) {
+            close();
+            throw new SocketTimeoutException(buildConnectFailureMessage(address, port, timeout, e.getMessage()));
+
+        } catch (ProtocolException e) {
+            close();
+            throw new ProtocolException(buildConnectFailureMessage(address, port, timeout, e.getMessage()));
+
         } catch (IOException e) {
             close();
             throw e;
         }
     }
 
+    private static String buildConnectFailureMessage(
+            InetAddress address, int port, int timeout, String rootCauseMessage) {
+
+        return String.format("%s: %s:%s, timeout %s",
+                (rootCauseMessage != null ? rootCauseMessage : "Failure connecting"),
+                address,
+                port,
+                timeout);
+    }
+
     /**
      * Binds the socket to the specified address of the specified local port.
      * @param address the address
