From 361eba435593bd43a91322b315136e511eb34cfd Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 1 Oct 2001 13:32:36 +0000 Subject: [PATCH] Make FileUtils.resolveFile more robust - modelled after File(File, String). This avoids the explicit checks for null directories in SourceFileScanner as well. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269755 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/ant/util/FileUtils.java | 11 ++++++++++- .../apache/tools/ant/util/SourceFileScanner.java | 14 ++------------ .../org/apache/tools/ant/util/FileUtilsTest.java | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java index 3e01bda5c..64e890ee2 100644 --- a/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/src/main/org/apache/tools/ant/util/FileUtils.java @@ -299,7 +299,9 @@ public class FileUtils { * @param file the "reference" file for relative paths. This * instance must be an absolute file and must not contain * "./" or "../" sequences (same for \ instead - * of /). + * of /). If it is null, this call is equivalent to + * new java.io.File(filename). + * * @param filename a file name * * @return an absolute file that doesn't contain "./" or @@ -327,6 +329,10 @@ public class FileUtils { return normalize(filename); } + if (file == null) { + return new File(filename); + } + File helpFile = new File(file.getAbsolutePath()); StringTokenizer tok = new StringTokenizer(filename, File.separator); while (tok.hasMoreTokens()) { @@ -361,6 +367,9 @@ public class FileUtils { *
  • DOS style paths that start with a drive letter will have * \ as the separator.
  • * + * + * @throws java.lang.NullPointerException if the file path is + * equal to null. */ public File normalize(String path) { String orig = path; diff --git a/src/main/org/apache/tools/ant/util/SourceFileScanner.java b/src/main/org/apache/tools/ant/util/SourceFileScanner.java index ac15e414a..9378cd3b7 100644 --- a/src/main/org/apache/tools/ant/util/SourceFileScanner.java +++ b/src/main/org/apache/tools/ant/util/SourceFileScanner.java @@ -121,12 +121,7 @@ public class SourceFileScanner { continue; } - File src = null; - if (srcDir == null) { - src = new File(files[i]); - } else { - src = fileUtils.resolveFile(srcDir, files[i]); - } + File src = fileUtils.resolveFile(srcDir, files[i]); if (src.lastModified() > now) { task.log("Warning: "+files[i]+" modified in the future.", @@ -136,12 +131,7 @@ public class SourceFileScanner { boolean added = false; targetList.setLength(0); for (int j=0; !added && j