On Mon, 18 Oct 2021 16:03:35 GMT, Daniel Jeliński <d...@openjdk.java.net> wrote:

>> Per Java documentation, 
>> "[Error](https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/lang/Error.java#L30)
>>  [..] indicates serious problems that a reasonable application should not 
>> try to catch". Failure to enumerate network interfaces or addresses is not a 
>> serious enough situation; many applications can recover from this pretty 
>> easily.
>> 
>> All native methods (except `init()`) in 
>> [NetworkInterface](https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/net/NetworkInterface.java#L436)
>>  are declared with `throws SocketException`, so throwing SocketExceptions 
>> instead of Errors will match the declared interface.
>> 
>> Unix version of 
>> [NetworkInterface](https://github.com/openjdk/jdk/blob/master/src/java.base/unix/native/libnet/NetworkInterface.c#L1189)
>>  already throws `SocketException`s in similar situations, and does not throw 
>> `Error` under any circumstances.
>> 
>> I searched the bug database and mail archives, but could not find any 
>> discussion on the topic; if there's a reason to keep throwing `Error`s, I 
>> couldn't find it.
>> 
>> `tier1` tests pass, `java.net` tests pass. No new regression tests as I 
>> couldn't find any list of steps to reproduce the problem.
>> 
>> I don't have write access to JBS. I could use some help with creating a 
>> ticket.
>
> Daniel Jeliński has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Throw more specific exceptions

Updated the PR with more specific exception types. I'm still doing some 
printf-based testing / debugging. Observations so far:
- My assumption that WinXP file contained some ancient code was incorrect. The 
WinXP functions are used when NOT in `java.net.preferIPv4Stack` mode, and are 
the preferred / more modern way. Cost me a few sanity points when I first 
realized.
- `GetAdaptersAddresses` failures are generating correct exception types, but 
error message generated by `JNU_ThrowByNameWithMessageAndLastError` is not what 
I expected. Example:

java.net.SocketException: An address has not yet been associated with the 
network endpoint (IP Helper Library GetAdaptersAddresses function failed)

I expected the Windows error code to appear after my message, not before.
- `GetIpAddrTable` failures are working correctly in `java.net.preferIPv4Stack` 
mode; in default mode they crash the JVM (access violation in net.dll). 
Apparently some of the callers attempt to access result pointer even when 
`lookupIPAddrTable` fails.

I'll update when I know more.

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

PR: https://git.openjdk.java.net/jdk/pull/5956

Reply via email to