Browse Source

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
master
Stefan Bodewig 15 years ago
parent
commit
0c08ce1f0e
3 changed files with 38 additions and 0 deletions
  1. +4
    -0
      WHATSNEW
  2. +8
    -0
      src/main/org/apache/tools/ant/util/FileUtils.java
  3. +26
    -0
      src/tests/antunit/taskdefs/tempfile-test.xml

+ 4
- 0
WHATSNEW View File

@@ -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:
--------------



+ 8
- 0
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -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 {


+ 26
- 0
src/tests/antunit/taskdefs/tempfile-test.xml View File

@@ -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>

Loading…
Cancel
Save