-
Bug
-
Resolution: Fixed
-
P4
-
1.3.0
-
beta
-
sparc
-
solaris_2.5
Name: akR10050 Date: 07/11/2000
public static File java.io.File.createTempFile(*) methods does not react when
java.io.tmpdir property is changed. It seems like java.io.File does not take
runtime value of the java.io.tmpdir property, but uses own static field to
represent it. Below is the example of described behaviour:
--------------- Test.java ---------------
import java.io.File;
import java.io.IOException;
public class Test {
public static void main(String[] args) {
// try to set java.io.tmpdir property to some invalid value
String defaultTmpDir = null;
try {
defaultTmpDir = System.setProperty("java.io.tmpdir",
"someinvaliddir");
System.out.println("Default temporary-file directory is "
+ defaultTmpDir);
} catch (SecurityException se) {
System.out.println("ERROR: Grant access to set property");
return;
}
try {
// try to create temp file
System.out.println("Try to create temp file, java.io.tmpdir has "
+ "wrong value");
File.createTempFile("temp", null);
} catch (IOException ioe) {
System.out.println("IOException thrown, this is correct behaviour");
}
System.setProperty("java.io.tmpdir", defaultTmpDir);
try {
// try to create temp file once again, java.io.tmpdir is valid now
System.out.println("Try to create temp file, java.io.tmpdir has "
+ "default system value");
File.createTempFile("temp", null);
} catch (IOException ioe) {
System.out.println("FAIL: IOException thrown");
return;
}
System.out.println("PASS: temp file created");
}
}
------------- end of Test.java ----------
--------------- output ------------------
<kai@knight(pts/26).5 ~>
--> java -version
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, interpreted mode)
<kai@knight(pts/26).6 ~>
--> java Test
Default temporary-file directory is /var/tmp/
Try to create temp file, java.io.tmpdir has wrong value
IOException thrown, this is correct behaviour
Try to create temp file, java.io.tmpdir has default system value
FAIL: IOException thrown
---------- end of output ----------------
======================================================================