-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
20
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
tested on linux and windows
A DESCRIPTION OF THE PROBLEM :
java.io.File.createTempFile("xyz", ".tmp") uses default temp-dir event if
System.setProperty("java.io.tmpdir", ...); was set before.
It seems that this was changed between java 19 and 20
One possible change was in java.nio.file.TempFileHelper
from
private static final Path tmpdir = Paths.get(doPrivileged(new GetPropertyAction("java.io.tmpdir")));
to
private static final Path tmpdir = Path.of(StaticProperty.javaIoTmpDir());
StaticProperty is loaded very very early and therefore jdk.internal.util.StaticProperty.JAVA_IO_TMPDIR contains the default temp-dir.
-> I know that java.io.tmpdir has to be set early in application but currently even a simple main-method is not able to change the java.io.tmpdir (see steps to reproduce)
REGRESSION : Last worked in version 19
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
call System.setProperty("java.io.tmpdir", ...) on application start, create temp-file and check the directory.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
no exception
ACTUAL -
exception beginning with java 20
docker run -it --rm -v $PWD:/test -w /test eclipse-temurin:11-jdk sh -c "javac Test.java && java -cp . Test"
11.0.21
/tmpfoobar
/tmpfoobar/xyz12142257841535750632.tmp
docker run -it --rm -v $PWD:/test -w /test eclipse-temurin:17-jdk sh -c "javac Test.java && java -cp . Test"
17.0.9
/tmpfoobar
/tmpfoobar/xyz3659998787174078425.tmp
docker run -it --rm -v $PWD:/test -w /test eclipse-temurin:19-jdk sh -c "javac Test.java && java -cp . Test"
19.0.2
/tmpfoobar
/tmpfoobar/xyz16800814432785594764.tmp
docker run -it --rm -v $PWD:/test -w /test eclipse-temurin:20-jdk sh -c "javac Test.java && java -cp . Test"
20.0.2
/tmpfoobar
/tmp/xyz7255378145959570555.tmp
Exception in thread "main" java.lang.IllegalStateException: actual: /tmp, expected: /tmpfoobar
at Test.main(Test.java:14)
docker run -it --rm -v $PWD:/test -w /test eclipse-temurin:21-jdk sh -c "javac Test.java && java -cp . Test"
21.0.1
/tmpfoobar
/tmp/xyz1465904699981539377.tmp
Exception in thread "main" java.lang.IllegalStateException: actual: /tmp, expected: /tmpfoobar
at Test.main(Test.java:14)
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String[] args)
throws Exception
{
final java.io.File tmp = new java.io.File("/tmpfoobar");
tmp.mkdirs();
System.setProperty("java.io.tmpdir", tmp.getAbsolutePath());
java.io.File testFile = java.io.File.createTempFile("xyz", ".tmp");
System.out.println(System.getProperty("java.version"));
System.out.println(tmp.getAbsolutePath());
System.out.println(testFile);
if (!tmp.getAbsolutePath().equals(testFile.getParent()))
throw new IllegalStateException("actual: " + testFile.getParent() + ", expected: " + tmp.getAbsolutePath());
}
}
---------- END SOURCE ----------
FREQUENCY : always
tested on linux and windows
A DESCRIPTION OF THE PROBLEM :
java.io.File.createTempFile("xyz", ".tmp") uses default temp-dir event if
System.setProperty("java.io.tmpdir", ...); was set before.
It seems that this was changed between java 19 and 20
One possible change was in java.nio.file.TempFileHelper
from
private static final Path tmpdir = Paths.get(doPrivileged(new GetPropertyAction("java.io.tmpdir")));
to
private static final Path tmpdir = Path.of(StaticProperty.javaIoTmpDir());
StaticProperty is loaded very very early and therefore jdk.internal.util.StaticProperty.JAVA_IO_TMPDIR contains the default temp-dir.
-> I know that java.io.tmpdir has to be set early in application but currently even a simple main-method is not able to change the java.io.tmpdir (see steps to reproduce)
REGRESSION : Last worked in version 19
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
call System.setProperty("java.io.tmpdir", ...) on application start, create temp-file and check the directory.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
no exception
ACTUAL -
exception beginning with java 20
docker run -it --rm -v $PWD:/test -w /test eclipse-temurin:11-jdk sh -c "javac Test.java && java -cp . Test"
11.0.21
/tmpfoobar
/tmpfoobar/xyz12142257841535750632.tmp
docker run -it --rm -v $PWD:/test -w /test eclipse-temurin:17-jdk sh -c "javac Test.java && java -cp . Test"
17.0.9
/tmpfoobar
/tmpfoobar/xyz3659998787174078425.tmp
docker run -it --rm -v $PWD:/test -w /test eclipse-temurin:19-jdk sh -c "javac Test.java && java -cp . Test"
19.0.2
/tmpfoobar
/tmpfoobar/xyz16800814432785594764.tmp
docker run -it --rm -v $PWD:/test -w /test eclipse-temurin:20-jdk sh -c "javac Test.java && java -cp . Test"
20.0.2
/tmpfoobar
/tmp/xyz7255378145959570555.tmp
Exception in thread "main" java.lang.IllegalStateException: actual: /tmp, expected: /tmpfoobar
at Test.main(Test.java:14)
docker run -it --rm -v $PWD:/test -w /test eclipse-temurin:21-jdk sh -c "javac Test.java && java -cp . Test"
21.0.1
/tmpfoobar
/tmp/xyz1465904699981539377.tmp
Exception in thread "main" java.lang.IllegalStateException: actual: /tmp, expected: /tmpfoobar
at Test.main(Test.java:14)
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String[] args)
throws Exception
{
final java.io.File tmp = new java.io.File("/tmpfoobar");
tmp.mkdirs();
System.setProperty("java.io.tmpdir", tmp.getAbsolutePath());
java.io.File testFile = java.io.File.createTempFile("xyz", ".tmp");
System.out.println(System.getProperty("java.version"));
System.out.println(tmp.getAbsolutePath());
System.out.println(testFile);
if (!tmp.getAbsolutePath().equals(testFile.getParent()))
throw new IllegalStateException("actual: " + testFile.getParent() + ", expected: " + tmp.getAbsolutePath());
}
}
---------- END SOURCE ----------
FREQUENCY : always
- relates to
-
JDK-8245194 Unix domain socket channel implementation
- Resolved
-
JDK-8290313 Produce warning when user specified java.io.tmpdir directory doesn't exist
- Closed