diff --git a/src/java.base/share/classes/sun/net/util/SocketExceptions.java b/src/java.base/share/classes/sun/net/util/SocketExceptions.java index a47811fe80c..ee70c58b9ba 100644 --- a/src/java.base/share/classes/sun/net/util/SocketExceptions.java +++ b/src/java.base/share/classes/sun/net/util/SocketExceptions.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -67,16 +67,7 @@ public final class SocketExceptions { } private static IOException ofInet(IOException e, InetSocketAddress addr) { - int port = addr.getPort(); - String host = addr.getHostString(); - StringBuilder sb = new StringBuilder(); - sb.append(e.getMessage()); - sb.append(": "); - sb.append(host); - sb.append(':'); - sb.append(Integer.toString(port)); - String enhancedMsg = sb.toString(); - return create(e, enhancedMsg); + return create(e, String.join(": ", e.getMessage(), addr.toString())); } private static IOException ofUnixDomain(IOException e, UnixDomainSocketAddress addr) { diff --git a/test/jdk/java/net/Socket/ExceptionText.java b/test/jdk/java/net/Socket/ExceptionText.java index c731b49e665..7f565e9777c 100644 --- a/test/jdk/java/net/Socket/ExceptionText.java +++ b/test/jdk/java/net/Socket/ExceptionText.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, 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 @@ -57,6 +57,7 @@ */ import java.io.IOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.nio.channels.AsynchronousSocketChannel; @@ -83,6 +84,7 @@ public class ExceptionText { static final InetSocketAddress dest = Utils.refusingEndpoint(); static final String PORT = ":" + Integer.toString(dest.getPort()); static final String HOST = dest.getHostString(); + static final InetAddress ADDRESS = dest.getAddress(); static void test(boolean withProperty) { // Socket @@ -104,11 +106,11 @@ public class ExceptionText { throw new RuntimeException("Test failed: exception contains address info"); } } else { - if (!msg.contains(HOST) || !msg.contains(PORT)) { + if (!msg.contains(HOST) || !msg.contains(PORT) || + !msg.contains(ADDRESS.getHostAddress())) { if (e instanceof ClosedChannelException) return; // has no detail msg - System.err.println("msg = " + msg); - throw new RuntimeException("Test failed: exception does not contain address info"); + throw new RuntimeException("Test failed: message '" + msg + "' is missing address info " + dest); } } }