Browse Source

URLResource#isExists returns true for non-existent http and ftp URLs, based on patch by Anthony Wat, PR 51110

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1577796 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 11 years ago
parent
commit
2d283dd117
2 changed files with 17 additions and 0 deletions
  1. +3
    -0
      WHATSNEW
  2. +14
    -0
      src/main/org/apache/tools/ant/types/resources/URLResource.java

+ 3
- 0
WHATSNEW View File

@@ -94,6 +94,9 @@ Fixed bugs:
implementations that encode big numbers by not adding a trailing implementations that encode big numbers by not adding a trailing
NUL. NUL.


* the isExists() method of URLResource returned false positives for
HTTP and FTP URLs.

Other changes: Other changes:
-------------- --------------




+ 14
- 0
src/main/org/apache/tools/ant/types/resources/URLResource.java View File

@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@@ -227,6 +228,19 @@ public class URLResource extends Resource implements URLProvider {
} }
try { try {
connect(Project.MSG_VERBOSE); connect(Project.MSG_VERBOSE);
if (conn instanceof HttpURLConnection) {
int sc = ((HttpURLConnection) conn).getResponseCode();
// treating inaccessible resources as non-existent
return sc < 400;
} else if (url.getProtocol().startsWith("ftp")) {
closeConnection = true;
InputStream in = null;
try {
in = conn.getInputStream();
} finally {
FileUtils.close(in);
}
}
return true; return true;
} catch (IOException e) { } catch (IOException e) {
return false; return false;


Loading…
Cancel
Save