RFR: 8227493: Return a more useful error message from lookupAllHostAddr if getaddrinfo results in EAI_SYSTEM error
Jaikiran Pai
jpai at openjdk.org
Mon Dec 2 13:58:51 UTC 2024
Can I please get a review of this minor enhancement to the error text that is reported if the `getaddrinfo()` native call returns the `EAI_SYSTEM` error? This addresses https://bugs.openjdk.org/browse/JDK-8227493.
The `java.net.InetAddress` class, in its implementation for resolving addresses for a host name, calls the `getaddrinfo()` native call on *nix platforms. If `getaddrinfo()` returns an error then we use the `gai_strerror()` native call to convert the error number into an error string that is then propagated to the application. Among other errors, the `getaddrinfo()` is specified to return the error code `EAI_SYSTEM` which as per its documentation represents
> EAI_SYSTEM system error returned in errno
So calling `gai_strerror()` merely returns a generic "System error" text. The real underlying error is present in the `errno` and that has more useful information.
The commit in this PR checks the error for `EAI_SYSTEM` and if it matches then it additionally gets the error text corresponding to `errno`. So the error text that gets propagated will now be "System error: Illegal byte sequence", assuming `EILSEQ` was the underlying `errno` for the `getaddrinfo` call (my use of `EILSEQ` in this example is arbitrary and it's merely to show what the error text will look like after this change).
Given the nature of this change no new test has been introduced. Existing tests in tier1, tier2 and tier3 continue to pass with this change.
-------------
Commit messages:
- 8227493: lookupAllHostAddr does not handle EAI_SYSTEM correctly
Changes: https://git.openjdk.org/jdk/pull/22484/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=22484&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8227493
Stats: 34 lines in 4 files changed: 19 ins; 0 del; 15 mod
Patch: https://git.openjdk.org/jdk/pull/22484.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/22484/head:pull/22484
PR: https://git.openjdk.org/jdk/pull/22484
More information about the net-dev
mailing list