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-ffa450edef68master
@@ -299,7 +299,9 @@ public class FileUtils { | |||||
* @param file the "reference" file for relative paths. This | * @param file the "reference" file for relative paths. This | ||||
* instance must be an absolute file and must not contain | * instance must be an absolute file and must not contain | ||||
* "./" or "../" sequences (same for \ instead | * "./" or "../" sequences (same for \ instead | ||||
* of /). | |||||
* of /). If it is null, this call is equivalent to | |||||
* <code>new java.io.File(filename)</code>. | |||||
* | |||||
* @param filename a file name | * @param filename a file name | ||||
* | * | ||||
* @return an absolute file that doesn't contain "./" or | * @return an absolute file that doesn't contain "./" or | ||||
@@ -327,6 +329,10 @@ public class FileUtils { | |||||
return normalize(filename); | return normalize(filename); | ||||
} | } | ||||
if (file == null) { | |||||
return new File(filename); | |||||
} | |||||
File helpFile = new File(file.getAbsolutePath()); | File helpFile = new File(file.getAbsolutePath()); | ||||
StringTokenizer tok = new StringTokenizer(filename, File.separator); | StringTokenizer tok = new StringTokenizer(filename, File.separator); | ||||
while (tok.hasMoreTokens()) { | while (tok.hasMoreTokens()) { | ||||
@@ -361,6 +367,9 @@ public class FileUtils { | |||||
* <li>DOS style paths that start with a drive letter will have | * <li>DOS style paths that start with a drive letter will have | ||||
* \ as the separator.</li> | * \ as the separator.</li> | ||||
* </ul> | * </ul> | ||||
* | |||||
* @throws java.lang.NullPointerException if the file path is | |||||
* equal to null. | |||||
*/ | */ | ||||
public File normalize(String path) { | public File normalize(String path) { | ||||
String orig = path; | String orig = path; | ||||
@@ -121,12 +121,7 @@ public class SourceFileScanner { | |||||
continue; | 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) { | if (src.lastModified() > now) { | ||||
task.log("Warning: "+files[i]+" modified in the future.", | task.log("Warning: "+files[i]+" modified in the future.", | ||||
@@ -136,12 +131,7 @@ public class SourceFileScanner { | |||||
boolean added = false; | boolean added = false; | ||||
targetList.setLength(0); | targetList.setLength(0); | ||||
for (int j=0; !added && j<targets.length; j++) { | for (int j=0; !added && j<targets.length; j++) { | ||||
File dest = null; | |||||
if (destDir == null) { | |||||
dest = new File(targets[j]); | |||||
} else { | |||||
dest = fileUtils.resolveFile(destDir, targets[j]); | |||||
} | |||||
File dest = fileUtils.resolveFile(destDir, targets[j]); | |||||
if (!dest.exists()) { | if (!dest.exists()) { | ||||
task.log(files[i]+" added as "+dest.getAbsolutePath()+" doesn\'t exist.", | task.log(files[i]+" added as "+dest.getAbsolutePath()+" doesn\'t exist.", | ||||
@@ -258,6 +258,21 @@ public class FileUtilsTest extends TestCase { | |||||
} | } | ||||
} | } | ||||
/** | |||||
* Test handling of null arguments. | |||||
*/ | |||||
public void testNullArgs() { | |||||
try { | |||||
fu.normalize(null); | |||||
fail("successfully normalized a null-file"); | |||||
} catch (NullPointerException npe) { | |||||
// Expected exception caught | |||||
} | |||||
File f = fu.resolveFile(null, "a"); | |||||
assertEquals(f, new File("a")); | |||||
} | |||||
/** | /** | ||||
* adapt file separators to local conventions | * adapt file separators to local conventions | ||||
*/ | */ | ||||