Throw a IllegalArgumentException instead of
NullPointerException in FileSystemUtils.freeSpaceWindows().
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -50,6 +50,9 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="IO-542" dev="pschumacher" type="update" due-to="Ilmars Poikans">
FileUtils#readFileToByteArray: optimize reading of files with known size
</action>
+ <action issue="IO-547" dev="ggregory" type="update" due-to="Nikhil Shinde, Michael Ernst, Gary Greory">
+ Throw a IllegalArgumentException instead of NullPointerException in FileSystemUtils.freeSpaceWindows().
+ </action>
<action issue="IO-367" dev="pschumacher" type="add" due-to="James Sawle">
Add convenience methods for copyToDirectory
</action>

MODIFY
src/main/java/org/apache/commons/io/FileSystemUtils.java
src/main/java/org/apache/commons/io/FileSystemUtils.java
@@ -294,13 +294,16 @@ long freeSpaceOS(final String path, final int os, final boolean kb, final long t
* @throws IOException if an error occurs
*/
long freeSpaceWindows(String path, final long timeout) throws IOException {
- path = FilenameUtils.normalize(path, false);
- if (path.length() > 0 && path.charAt(0) != '"') {
- path = "\"" + path + "\"";
+ String normPath = FilenameUtils.normalize(path, false);
+ if (normPath == null) {
+ throw new IllegalArgumentException(path);
+ }
+ if (normPath.length() > 0 && normPath.charAt(0) != '"') {
+ normPath = "\"" + normPath + "\"";
}
// build and run the 'dir' command
- final String[] cmdAttribs = new String[] {"cmd.exe", "/C", "dir /a /-c " + path};
+ final String[] cmdAttribs = new String[] {"cmd.exe", "/C", "dir /a /-c " + normPath};
// read in the output of the command to an ArrayList
final List<String> lines = performCommand(cmdAttribs, Integer.MAX_VALUE, timeout);
@@ -312,13 +315,13 @@ long freeSpaceWindows(String path, final long timeout) throws IOException {
for (int i = lines.size() - 1; i >= 0; i--) {
final String line = lines.get(i);
if (line.length() > 0) {
- return parseDir(line, path);
+ return parseDir(line, normPath);
}
}
// all lines are blank
throw new IOException(
"Command line 'dir /-c' did not return any info " +
- "for path '" + path + "'");
+ "for path '" + normPath + "'");
}
/**

[IO-547] Throw a IllegalArgumentException instead of
NullPointerException in FileSystemUtils.freeSpaceWindows().