Skip to content

Commit

Permalink
8299827: Add resolved IP address in connection exception for sockets
Browse files Browse the repository at this point in the history
Backport-of: 92d8326e4037605897d7c4eb4b3edb63a2fc11b0
  • Loading branch information
Andrey Turbanov authored and TheRealMDoerr committed Aug 24, 2023
1 parent e830464 commit 40add10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
13 changes: 2 additions & 11 deletions 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
Expand Down Expand Up @@ -67,16 +67,7 @@ public static IOException of(IOException e, SocketAddress addr) {
}

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) {
Expand Down
10 changes: 6 additions & 4 deletions 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
Expand Down Expand Up @@ -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;
Expand All @@ -83,6 +84,7 @@ public static void main(String args[]) throws Exception {
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
Expand All @@ -104,11 +106,11 @@ static void checkResult(IOException e, boolean withProperty) {
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);
}
}
}
Expand Down

3 comments on commit 40add10

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schmelter-sap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 40add10 Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schmelter-sap Could not automatically backport 40add10f to openjdk/jdk11u-dev due to conflicts in the following files:

  • src/java.base/share/classes/sun/net/util/SocketExceptions.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b schmelter-sap-backport-40add10f

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk17u-dev.git 40add10f8ba99ee3da50e07c30340a8e15a7b86c

# Backport the commit
$ git cherry-pick --no-commit 40add10f8ba99ee3da50e07c30340a8e15a7b86c
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 40add10f8ba99ee3da50e07c30340a8e15a7b86c'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport 40add10f8ba99ee3da50e07c30340a8e15a7b86c.

Please sign in to comment.