diff --git a/WHATSNEW b/WHATSNEW index 0ec0b5114..166dcd4cf 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -52,6 +52,11 @@ Fixed bugs: if failOnError was set to false. Bugzilla Report 63071 + * The isreachable condition could in some cases return true even if the + actual address could potentially be unreachable. This is now fixed + and the resolved address is actually checked for reachability. + + Other changes: -------------- * generatekey task now supports SubjectAlternativeName during key diff --git a/manual/Tasks/conditions.html b/manual/Tasks/conditions.html index d1d2e4519..97264f1dd 100644 --- a/manual/Tasks/conditions.html +++ b/manual/Tasks/conditions.html @@ -576,10 +576,7 @@ specifications, by attempting to set the appropriate property/feature
Uses Java 5+ networking APIs to probe for a (remote) system being reachable. Exactly what probe mechanisms are used is an implementation feature of the JVM. They may include ICMP "ping" packets, -UDP or TCP connections to port 7 "echo service" or other means. On Java 1.4 and earlier, being able -to resolve the hostname is considered success. This means that if DNS is not working or a -URL/hostname is bad, the test will fail, but otherwise succeed even if the remote host is actually -absent.
+UDP or TCP connections to port 7 "echo service" or other means.This condition turns unknown host exceptions into false conditions. This is because on a laptop, DNS is one of the first services when the network goes; you are implicitly offline.
If a URL is supplied instead of a host, the hostname is extracted and used in the diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java b/src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java index e78d94bdf..e508a1caa 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java @@ -18,6 +18,7 @@ package org.apache.tools.ant.taskdefs.condition; +import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.InetAddress; @@ -85,7 +86,11 @@ public class IsReachable extends ProjectComponent implements Condition { public static final String ERROR_BAD_URL = "Bad URL "; /** Error message when no hostname in url. */ public static final String ERROR_NO_HOST_IN_URL = "No hostname in URL "; - /** The method name to look for in InetAddress */ + /** + * The method name to look for in InetAddress + * @deprecated Since 1.10.6 + */ + @Deprecated public static final String METHOD_NAME = "isReachable"; private String host; @@ -174,28 +179,11 @@ public class IsReachable extends ProjectComponent implements Condition { log("Host address = " + address.getHostAddress(), Project.MSG_VERBOSE); boolean reachable; - //Java1.5: reachable = address.isReachable(timeout * 1000); try { - Method reachableMethod = - InetAddress.class.getMethod(METHOD_NAME, Integer.class); - try { - reachable = (Boolean) reachableMethod.invoke(address, - timeout * SECOND); - } catch (final IllegalAccessException e) { - //utterly implausible, but catered for anyway - throw new BuildException("When calling " + reachableMethod); - } catch (final InvocationTargetException e) { - //assume this is an IOException about un readability - final Throwable nested = e.getTargetException(); - log(ERROR_ON_NETWORK + target + ": " + nested.toString()); - //any kind of fault: not reachable. - reachable = false; - } - } catch (final NoSuchMethodException e) { - //java1.4 - log("Not found: InetAddress." + METHOD_NAME, Project.MSG_VERBOSE); - log(MSG_NO_REACHABLE_TEST); - reachable = true; + reachable = address.isReachable(timeout * SECOND); + } catch (final IOException ioe) { + reachable = false; + log(ERROR_ON_NETWORK + target + ": " + ioe.toString()); } log("host is" + (reachable ? "" : " not") + " reachable", Project.MSG_VERBOSE);