From 0c08ce1f0e9880b5f3a6c3c37008acccd5f97392 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 17 Aug 2010 07:57:18 +0000 Subject: [PATCH] Avoid NPE in createTempFile if no prfix has been specified. PR 49755 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@986226 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 4 +++ .../org/apache/tools/ant/util/FileUtils.java | 8 ++++++ src/tests/antunit/taskdefs/tempfile-test.xml | 26 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/tests/antunit/taskdefs/tempfile-test.xml diff --git a/WHATSNEW b/WHATSNEW index c6c27fc6c..e4e82b445 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -119,6 +119,10 @@ Fixed bugs: s that used the prefix or fullpath attributes. Bugzilla Report 49605. + * would cause an error unless the prefix + attribute has been specified. + Bugzilla Report 49755. + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java index fe1b6859a..38b82f9dc 100644 --- a/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/src/main/org/apache/tools/ant/util/FileUtils.java @@ -898,6 +898,8 @@ public class FileUtils { return createTempFile(prefix, suffix, parentDir, false, false); } + private static final String NULL_PLACEHOLDER = "null"; + /** * Create a temporary file in a given directory. * @@ -925,6 +927,12 @@ public class FileUtils { String parent = (parentDir == null) ? System.getProperty("java.io.tmpdir") : parentDir.getPath(); + if (prefix == null) { + prefix = NULL_PLACEHOLDER; + } + if (suffix == null) { + suffix = NULL_PLACEHOLDER; + } if (createFile) { try { diff --git a/src/tests/antunit/taskdefs/tempfile-test.xml b/src/tests/antunit/taskdefs/tempfile-test.xml new file mode 100644 index 000000000..2749216dc --- /dev/null +++ b/src/tests/antunit/taskdefs/tempfile-test.xml @@ -0,0 +1,26 @@ + + + + + + + + + +