On Fri, 9 Aug 2024 15:09:08 GMT, Brian Burkhalter <b...@openjdk.org> wrote:

>> OK, this test uses a private API to create an instance of Inet6AddressImpl; 
>> This explain why in this test Inet6AddressImpl gets loaded before 
>> InetAddress.
>> 
>>             var impl = new Inet6AddressImpl();
>> 
>> It should never happen outside of this test. Now the tricky question: what 
>> in your proposed changes caused "net" not to be loaded before the test 
>> created new Inet6AddressImpl(); ?
>
> Loading "net" was removed from IOUtil so I am thinking that IOUtil must have 
> been initialized somewhere before constructing Inet6AddressImpl, but I've not 
> identified where just yet.

I see. Inet6AddressImpl and Inet4AddressImpl are symetric classes implementing 
InetAddressImpl. Both will make native calls to the "net" library - so both 
require the library to be loaded.

In the JDK, these two classes are only loaded by InetAddress, after the "net" 
library has been loaded.

The test test java/net/InetAddress/NullCharInHostnameDriver.java seems to be an 
outlier (@AlekseiEfimov ?) which for some reason uses a private API (the test 
is injected in java.base) and create a new instance of Inet6AddressImpl before 
InetAddress is loaded. This is why without this change to Inet6AddressImpl we 
get the UnsatisfiedLinkError. We would have gotten the same from 
Inet4AddressImpl if the test had first required access to Inet4AddressImpl 
instead.

So it seems that we should either add the call to load the "net" library to 
both Inet6AddressImpl and Inet4AddressImpl for symetry (there doesn't seem to 
be any reason why Inet6AddressImpl would be preferred in this respect),  or 
remove this call from Inet6AddressImpl and add it to the test instead. Adding 
the call to jdk.internal.loader.BootLoader.loadLibrary("net"); in the test 
should work since the actual test class (NullCharInHostname.java) is injected 
in java.base.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/20317#discussion_r1711706176

Reply via email to