You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2017/09/07 19:33:09 UTC
commons-io git commit: [IO-547] Throw a IllegalArgumentException
instead of NullPointerException in FileSystemUtils.freeSpaceWindows().
Repository: commons-io
Updated Branches:
refs/heads/master 92a07f9aa -> 5899f1eb7
[IO-547] Throw a IllegalArgumentException instead of
NullPointerException in FileSystemUtils.freeSpaceWindows().
Project: http://git-wip-us.apache.org/repos/asf/commons-io/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-io/commit/5899f1eb
Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/5899f1eb
Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/5899f1eb
Branch: refs/heads/master
Commit: 5899f1eb7239ea26291b9e38490f5922b86158d8
Parents: 92a07f9
Author: Gary Gregory <ga...@gmail.com>
Authored: Thu Sep 7 13:33:07 2017 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Thu Sep 7 13:33:07 2017 -0600
----------------------------------------------------------------------
src/changes/changes.xml | 3 +++
.../java/org/apache/commons/io/FileSystemUtils.java | 15 +++++++++------
2 files changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-io/blob/5899f1eb/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6350730..490c05e 100644
--- a/src/changes/changes.xml
+++ b/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>
http://git-wip-us.apache.org/repos/asf/commons-io/blob/5899f1eb/src/main/java/org/apache/commons/io/FileSystemUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/io/FileSystemUtils.java b/src/main/java/org/apache/commons/io/FileSystemUtils.java
index ceabd80..a560c0b 100644
--- a/src/main/java/org/apache/commons/io/FileSystemUtils.java
+++ b/src/main/java/org/apache/commons/io/FileSystemUtils.java
@@ -294,13 +294,16 @@ public class FileSystemUtils {
* @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 @@ public class FileSystemUtils {
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 + "'");
}
/**