RFR: 7903988: IDEA plugin: temp directories don't work on Windows

Christian Stein cstein at openjdk.org
Mon Apr 14 16:32:59 UTC 2025


On Sat, 12 Apr 2025 18:21:38 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

> Copied from the JBS issue:
> 
> To find the temporary directory on Windows, one of the environment variables `TMP`, `TEMP`, or `USERPROFILE` is needed [1](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppatha#remarks). If these are not set, `C:\WINDOWS` is used as a fallback, but this directory is typically inaccessible (and generally not really a directory you want to leave temp files in).
> 
> The IDEA plugin currently doesn't forward these variables to the jtreg process that it starts, resulting in them being unset. For tests that e.g. create temporary files or directories, this result in an `AccessDeniedException` such as:
> 
> 
> java.nio.file.AccessDeniedException: C:\\WINDOWS\\asdf12599356154200781179
>   at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
>   at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
>   at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
>   at java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:231)
>   at java.base/java.nio.file.Files.newByteChannel(Files.java:357)
>   at java.base/java.nio.file.Files.createFile(Files.java:609)
>   at java.base/java.nio.file.TempFileHelper.create(TempFileHelper.java:132)
>   at java.base/java.nio.file.TempFileHelper.createTempFile(TempFileHelper.java:150)
>   at java.base/java.nio.file.Files.createTempFile(Files.java:842)
>   at TestTempDir.testTempDir(TestTempDir.java:39)
> 
> 
> The plugin should forward these environment variables on Windows, to make sure that the temporary directory can be found by tests.
> 
> Tested locally with a simple test that calls [`Files::createTempFile`](https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/nio/file/Files.html#createTempFile(java.lang.String,java.lang.String,java.nio.file.attribute.FileAttribute...)), and checked that these changes prevent an `AccessDeniedError` from being thrown.

plugins/idea/src/main/java/com/oracle/plugin/jtreg/configuration/JTRegConfigurationRunnableState.java line 41:

> 39: import com.intellij.openapi.module.Module;
> 40: import com.intellij.util.PathUtil;
> 41: import com.oracle.plugin.jtreg.util.JTRegUtils;

Nit: please move this line to the other `com.oracle.plugin.jtreg...` imports.

plugins/idea/src/main/java/com/oracle/plugin/jtreg/configuration/JTRegConfigurationRunnableState.java line 111:

> 109:         javaParameters.setMainClass("com.sun.javatest.regtest.Main");
> 110: 
> 111:         if (JTRegUtils.IS_WINDOWS) {

What happens if `System.getenv("TMP")` returns `null`?

Wouldn't it be better to check that first for each pair, and if the value is non-null, add the pair to the  `javaParameters` instance?

-------------

PR Review Comment: https://git.openjdk.org/jtreg/pull/258#discussion_r2042497165
PR Review Comment: https://git.openjdk.org/jtreg/pull/258#discussion_r2042500219


More information about the jtreg-dev mailing list