JDK-7118907 : InetAddress.isReachable() should return false if sendto fails with EHOSTUNREACH
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-12-07
  • Updated: 2013-06-26
  • Resolved: 2011-12-26
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 7 JDK 8
7u40Fixed 8 b19Fixed
Description
On some Linuxes, when bound to the loopback interface, sendto may fail with an EINVAL errno (see CR 6947677), and on others (AIX, iSeries) it will throw an EHOSTUNREACH errno. In such situation, EHOSTUNREACH should be treated the same as EINVAL, not 
throw an exception but return false.

Below is the simple testcase that can demonstrate this on specific platforms:

public class IsReachableTest {
     public static void main(String[] args) throws Exception{
         InetAddress testHost1 = InetAddress.getByName("openjdk.java.net");
         NetworkInterface loopbackNi = null;
         Enumeration<NetworkInterface> list =
             NetworkInterface.getNetworkInterfaces();
         boolean loopbackFound = false;
         while (list.hasMoreElements() && !loopbackFound){
             loopbackNi = list.nextElement();
             if (loopbackNi.isLoopback() && loopbackNi.isUp()) {
                 loopbackFound = true;
             }
         }

         if (!loopbackFound)
             return;
         if (testHost1.isReachable(loopbackNi, 64, 1000))
             System.out.println(String.format("Fail: external host '%s' is reachable via loopback '%s'!", testHost1, loopbackNi));
     }
}

see the mail thread on the net-dev mailing list for further details:
  http://mail.openjdk.java.net/pipermail/net-dev/2011-December/003839.html

Comments
EVALUATION Changeset: c508f38245f8 Author: ngmr Date: 2011-12-12 11:41 +0000 URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/c508f38245f8 7118907: InetAddress.isReachable() should return false if sendto fails with EHOSTUNREACH Reviewed-by: alanb, chegar Contributed-by: Charles Lee <###@###.###> ! src/solaris/native/java/net/Inet4AddressImpl.c ! src/solaris/native/java/net/Inet6AddressImpl.c
12-12-2011