JDK-8205076 : [17u] Inet6AddressImpl.c: `lookupIfLocalHost` accesses `int InetAddress.preferIPv6Address` as a boolean
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 11,17
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • Submitted: 2018-06-14
  • Updated: 2024-06-17
  • Resolved: 2024-01-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 17
11.0.25Fixed 17.0.11 b01Fixed
Related Reports
Duplicate :  
Relates :  
Description
In 

    http://hg.openjdk.java.net/jdk/jdk/file/64ca9fbcf85f/src/java.base/unix/native/libnet/Inet6AddressImpl.c#l172
    if ((*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID)) {

That is `InetAddress.preferIPv6Address` is used as a boolean, but 

    http://hg.openjdk.java.net/jdk/jdk/file/64ca9fbcf85f/src/java.base/share/classes/java/net/InetAddress.java#l216
    /* Specify address family preference */
    static transient final int preferIPv6Address;

That is, it is an `int`.  (In JDK-8 it was a `boolean`.)

I don't know how `GetStaticBoolean` deals with a mismatch in types.  The result will be interpreted by the `C` 0-or-not-0 test.  I don't know if that is what is needed here.

(Note that this is inside a `#if defined(MACOSX)` block.)
Comments
[jdk11u-fix-request] Approval Request from Aleksey Shipilëv Backport for 11u/17u-specific fix, does what upstream code already do post JDK 18, and in JDK 17. Testing passes on platform where tests used to fail.
13-06-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk11u-dev/pull/2769 Date: 2024-06-13 14:07:50 +0000
13-06-2024

Changeset: 3eb15b02 Author: Aleksey Shipilev <shade@openjdk.org> Date: 2024-01-03 10:50:00 +0000 URL: https://git.openjdk.org/jdk17u/commit/3eb15b02b5efeb065ada8c6ae2bc8718e7892deb
31-01-2024

Changeset: 3eb15b02 Author: Aleksey Shipilev <shade@openjdk.org> Date: 2024-01-03 10:50:00 +0000 URL: https://git.openjdk.org/jdk17u-dev/commit/3eb15b02b5efeb065ada8c6ae2bc8718e7892deb
03-01-2024

[jdk17u-fix-request] Approval Request from Aleksey Shipilëv 17u-specific fix, does what upstream code already do post JDK 18. Testing passes on platform where tests used to fail.
19-12-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/2048 Date: 2023-12-12 15:17:37 +0000
12-12-2023

This is still a bug in 11u and 17u. Caught this while running -Xcheck:jni tests on 17u: $ CONF=macosx-aarch64-server-fastdebug make images test TEST=com/sun/management/DiagnosticCommandMBean/DcmdMBeanTestCheckJni.java ... STDERR: stdout: [FATAL ERROR in native method: Field type (static) mismatch in JNI get/set field operations at java.net.Inet6AddressImpl.lookupAllHostAddr(java.base@17.0.11-internal/Native Method) at java.net.InetAddress$PlatformNameService.lookupAllHostAddr(java.base@17.0.11-internal/InetAddress.java:934) at java.net.InetAddress.getAddressesFromNameService(java.base@17.0.11-internal/InetAddress.java:1543) at java.net.InetAddress$NameServiceAddresses.get(java.base@17.0.11-internal/InetAddress.java:852) - locked <0x00000007efc517f8> (a java.net.InetAddress$NameServiceAddresses) at java.net.InetAddress.getAllByName0(java.base@17.0.11-internal/InetAddress.java:1533) at java.net.InetAddress.getLocalHost(java.base@17.0.11-internal/InetAddress.java:1666) at javax.management.remote.JMXServiceURL.<init>(java.management@17.0.11-internal/JMXServiceURL.java:299) at javax.management.remote.JMXServiceURL.<init>(java.management@17.0.11-internal/JMXServiceURL.java:262) at DcmdMBeanRunner.main(DcmdMBeanTestCheckJni.java:66) ]; stderr: [] exitValue = 134 This is because `InetAddress.preferIPv6Addresses` is `int`: https://github.com/openjdk/jdk17u-dev/blob/959665633eae0923d8acce533834940d1797bffd/src/java.base/share/classes/java/net/InetAddress.java#L218 ...but we access it as `boolean`: https://github.com/openjdk/jdk17u-dev/blob/959665633eae0923d8acce533834940d1797bffd/src/java.base/unix/native/libnet/Inet6AddressImpl.c#L154 Indeed JDK-8244202 changed the problematic spot to: https://github.com/openjdk/jdk/blob/5718039a46ae51fa9b7042fe7163e3637e981b05/src/java.base/unix/native/libnet/Inet6AddressImpl.c#L155
12-12-2023

The last remaining use of ia_preferIPv6AddressID was removed in JDK-8244202; closing.
28-02-2023

i will look into this.
24-08-2018

Daniel, not sure if you're the right assignee, but I think you're one step closer. :-)
27-06-2018

How did this end up in the hotspot/compiler category (which is for the HotSpot JIT compilers)?
27-06-2018