This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new 19319ea Fix SpotBugs issues in org.apache.commons.io.FileUtils.
19319ea is described below
commit 19319eada154fa9fdb41a72cc88be2aecf549355
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Jul 1 13:16:07 2020 -0400
Fix SpotBugs issues in org.apache.commons.io.FileUtils.
---
src/changes/changes.xml | 3 +++
src/main/java/org/apache/commons/io/FileUtils.java | 19 +++++++++++++------
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 08771a0..f2f9516 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -71,6 +71,9 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="fix" due-to="Gary Gregory">
Replace FindBugs with SpotBugs.
</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">
+ Fix SpotBugs issues in org.apache.commons.io.FileUtils.
+ </action>
</release>
<!-- The release date is the date RC is cut -->
<release version="2.7" date="2020-05-24" description="Java 8 required.">
diff --git a/src/main/java/org/apache/commons/io/FileUtils.java
b/src/main/java/org/apache/commons/io/FileUtils.java
index e5b1ee8..492886c 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -1237,10 +1237,11 @@ public class FileUtils {
* @param filter the filter to apply, null means copy all
directories and files
* @param preserveFileDate whether to preserve the file date
* @param exclusionList List of files and directories to exclude from
the copy, may be null
+ * @return whether the operation succeeded
* @throws IOException if an error occurs
* @since 1.1
*/
- private static void doCopyDirectory(final File srcDir, final File destDir,
final FileFilter filter,
+ private static boolean doCopyDirectory(final File srcDir, final File
destDir, final FileFilter filter,
final boolean preserveFileDate, final
List<String> exclusionList)
throws IOException {
// recurse
@@ -1273,8 +1274,9 @@ public class FileUtils {
// Do this last, as the above has probably affected directory metadata
if (preserveFileDate) {
- destDir.setLastModified(srcDir.lastModified());
+ return destDir.setLastModified(srcDir.lastModified());
}
+ return true;
}
/**
@@ -1288,13 +1290,14 @@ public class FileUtils {
* @param srcFile the validated source file, must not be {@code
null}
* @param destFile the validated destination file, must not be
{@code null}
* @param preserveFileDate whether to preserve the file date
+ * @return whether the operation succeeded
* @throws IOException if an error occurs
* @throws IOException if the output file length is not the
same as the input file length after the
* copy completes
* @throws IllegalArgumentException "Negative size" if the file is
truncated so that the size is less than the
* position
*/
- private static void doCopyFile(final File srcFile, final File destFile,
final boolean preserveFileDate)
+ private static boolean doCopyFile(final File srcFile, final File destFile,
final boolean preserveFileDate)
throws IOException {
if (destFile.exists() && destFile.isDirectory()) {
throw new IOException("Destination '" + destFile + "' exists but
is a directory");
@@ -1310,7 +1313,7 @@ public class FileUtils {
// TODO IO-386: Do we still need this check?
checkEqualSizes(srcFile, destFile, srcFile.length(),
destFile.length());
- destFile.setLastModified(newLastModifed);
+ return destFile.setLastModified(newLastModifed);
}
//-----------------------------------------------------------------------
@@ -1977,7 +1980,9 @@ public class FileUtils {
throws IOException {
validateMoveParameters(src, destDir);
if (!destDir.exists() && createDestDir) {
- destDir.mkdirs();
+ if (!destDir.mkdirs()) {
+ throw new IOException("Could not create destination
directories '" + destDir + "'");
+ }
}
if (!destDir.exists()) {
throw new FileNotFoundException("Destination directory '" +
destDir +
@@ -2042,7 +2047,9 @@ public class FileUtils {
throws IOException {
validateMoveParameters(srcFile, destDir);
if (!destDir.exists() && createDestDir) {
- destDir.mkdirs();
+ if (!destDir.mkdirs()) {
+ throw new IOException("Could not create destination
directories '" + destDir + "'");
+ }
}
if (!destDir.exists()) {
throw new FileNotFoundException("Destination directory '" +
destDir +