RFR: 8275319 java.net.NetworkInterface throws java.lang.Error instead of SocketException

Alan Bateman alanb at openjdk.java.net
Sat Oct 16 08:06:48 UTC 2021


On Thu, 14 Oct 2021 17:29:16 GMT, Daniel Jeliński <duke at 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.

JDK-8217298 hints that one scenario where an exception is thrown is when there are no network adapters configured. I don't know how easy it would be to create that scenario and to see how current JDK releases behave.

MultiByteToWideChar - yes, makes sense.

GetIfTable -yes, I agree this needs to cleaned up. I don't see ERROR_BUFFER_OVERFLOW listed as a possible error.

GetAdaptersAddresses. It would be nice if this NetworkInterface_winXP.c could be removed but it is still used for the  -Djava.net.preferIPv4Stack=true case. A more useful exercise may be to see if we could move to one implementation that works with preferIPv4Stack set to true or false.

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

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


More information about the net-dev mailing list