diff --git a/WHATSNEW b/WHATSNEW index 5c78ad10c..f53145f77 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -64,6 +64,12 @@ Fixed bugs: archive failed. Port of https://issues.apache.org/jira/browse/COMPRESS-297 + * FileUtils.rename which is used by several tasks can throw a + NullPointerException if the "normal" renameTo operation fails and + an exception occurs while rename falls back to copying and deleting + the file. + Bugzilla Report 57533 + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/util/ResourceUtils.java b/src/main/org/apache/tools/ant/util/ResourceUtils.java index 0c1ce691e..6397f714b 100644 --- a/src/main/org/apache/tools/ant/util/ResourceUtils.java +++ b/src/main/org/apache/tools/ant/util/ResourceUtils.java @@ -435,11 +435,15 @@ public class ResourceUtils { copyUsingFileChannels(sourceFile, destFile); copied = true; } catch (final IOException ex) { - project.log("Attempt to copy " + sourceFile - + " to " + destFile + " using NIO Channels" - + " failed due to '" + ex.getMessage() - + "'. Falling back to streams.", - Project.MSG_WARN); + String msg = "Attempt to copy " + sourceFile + + " to " + destFile + " using NIO Channels" + + " failed due to '" + ex.getMessage() + + "'. Falling back to streams."; + if (project != null) { + project.log(msg, Project.MSG_WARN); + } else { + System.err.println(msg); + } } } if (!copied) { @@ -828,8 +832,13 @@ public class ResourceUtils { if (a != null) { return a.getAppendOutputStream(); } - project.log("Appendable OutputStream not available for non-appendable resource " - + resource + "; using plain OutputStream", Project.MSG_VERBOSE); + String msg = "Appendable OutputStream not available for non-appendable resource " + + resource + "; using plain OutputStream"; + if (project != null) { + project.log(msg, Project.MSG_VERBOSE); + } else { + System.out.println(msg); + } } return resource.getOutputStream(); }