ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bck...@worldonline.dk (Finn Bock)
Subject [PATCH] for FileUtils.createTempFile under JDK1.1
Date Sun, 25 Nov 2001 19:45:19 GMT
Hi,

There is a bug in one of the the constructors of java.io.File in
JDK1.1.7a that will cause a NPE when called with a null parent 
directory File argument. 

Using the "new File(String, String)" constructor instead,
it is valid to pass a null parent dir, and that is what the
patch below is doing.

I encountered the NPE when running ant with JDK1.1.7 and using
jikes for an javac task.

regards,
finn


Index: src/main/org/apache/tools/ant/util/FileUtils.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/util/FileUtils.java,v
retrieving revision 1.10
diff -u -r1.10 FileUtils.java
--- src/main/org/apache/tools/ant/util/FileUtils.java	2001/11/19 14:15:43	1.10
+++ src/main/org/apache/tools/ant/util/FileUtils.java	2001/11/25 19:22:19
@@ -496,10 +496,14 @@
     public File createTempFile(String prefix, String suffix, File parentDir) {
 
         File result = null;
+        String parent = null;
+        if (parentDir != null) {
+            parent = parentDir.getPath();
+        }
         DecimalFormat fmt = new DecimalFormat("#####");
         synchronized (rand) {
             do {
-                result = new File(parentDir, 
+                result = new File(parent, 
                                   prefix + fmt.format(rand.nextInt()) 
                                   + suffix);
             } while (result.exists());


--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message