ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r986226 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/util/FileUtils.java src/tests/antunit/taskdefs/tempfile-test.xml
Date Tue, 17 Aug 2010 07:57:18 GMT
Author: bodewig
Date: Tue Aug 17 07:57:18 2010
New Revision: 986226

URL: http://svn.apache.org/viewvc?rev=986226&view=rev
Log:
Avoid NPE in createTempFile if no prfix has been specified.  PR 49755

Added:
    ant/core/trunk/src/tests/antunit/taskdefs/tempfile-test.xml   (with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=986226&r1=986225&r2=986226&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Aug 17 07:57:18 2010
@@ -119,6 +119,10 @@ Fixed bugs:
    <zipfileset>s that used the prefix or fullpath attributes.
    Bugzilla Report 49605.
 
+ * <tempfile createfile="true"> would cause an error unless the prefix
+   attribute has been specified.
+   Bugzilla Report 49755.
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java?rev=986226&r1=986225&r2=986226&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java Tue Aug 17 07:57:18 2010
@@ -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 {

Added: ant/core/trunk/src/tests/antunit/taskdefs/tempfile-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/tempfile-test.xml?rev=986226&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/tempfile-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/taskdefs/tempfile-test.xml Tue Aug 17 07:57:18 2010
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
+  <import file="../antunit-base.xml" />
+
+  <target name="testCreateWithoutPrefix"
+          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49755">
+    <tempfile property="tmp" createfile="true"/>
+    <au:assertFileExists file="${tmp}"/>
+  </target>
+</project>

Propchange: ant/core/trunk/src/tests/antunit/taskdefs/tempfile-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message