Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests that set java.io.tmp dir may pollute java.io.File.TempDirectory.tmpdir with a directory that doesn't exist #41905

Closed
wilkinsona opened this issue Aug 16, 2024 · 0 comments
Assignees
Labels
type: task A general task
Milestone

Comments

@wilkinsona
Copy link
Member

wilkinsona commented Aug 16, 2024

I'm seeing this in LogbackLoggingSystemTests but it could happen in any test that sets java.io.tmpdir. The pollution happens like this:

  1. A test's setup code setsjava.io.tmpdir to a JUnit-provided temporary directory
  2. Some code, a call to Files.createTempFile for example, causes java.io.File.TempDirectory to be loaded and its tmpdir static is set to the value of java.io.tmpdir
  3. A test's cleanup code restores java.io.tmpdir to its original value and JUnit deletes its temporary directory
  4. Some code tries to use Files.createTempFile and it fails because java.io.File.TempDirectory.tmpdir points to the directory that was deleted in step 3

Ideally, we'd avoid setting java.io.tmpdir in our tests. Failing that, we could ensure that java.io.File.TempDirectory has been initialized before we set it so that its tmpdir static doesn't get polluted with a custom directory that may only exist for the duration of a single test.

There's a similar problem with java.nio.file.TempFileHelper.tmpdir that's used by java.nio.file.Files.createTempFile(String, String, FileAttribute<?>...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

No branches or pull requests

1 participant