Skip to content

@TempDir directory cannot be deleted on Windows with Java 11 #2811

Description

I have a test that has been failing on windows-latest with Java 11 on GitHub Actions CI, but not on Java 17.

This is my test:

    @Test
    void canFetchArtifactToSpecificDir(@TempDir File tempDir) throws Exception {
        var outputDir = new File(tempDir, "outDir");
        final var expectedFileLocation = new File(outputDir, "opentest4j-1.2.0.pom");
        outputDir.deleteOnExit();
        expectedFileLocation.deleteOnExit();

        var result = runWithIntTestRepo("fetch", "org.opentest4j:opentest4j:1.2.0:pom",
                "-d", outputDir.getPath());
        verifySuccessful("jbuild fetch", result);

        assertThat(result.getStdout()).startsWith("JBuild success in ");
        assertThat(expectedFileLocation).isFile();

        try (var stream = new FileInputStream(expectedFileLocation)) {
            var pom = MavenUtils.parsePom(stream);
            assertThat(pom.getArtifact()).isEqualTo(new Artifact("org.opentest4j", "opentest4j", "1.2.0"));
        }
    }

I added those deleteOnExit calls to try to "help" JUnit to get rid of that temp dir, to no avail.

Link to GitHub Actions CI Log
Link to JUnit report

The error it shows:

❌ canFetchArtifactToSpecificDir(File)
	java.io.IOException: Failed to delete temp directory C:\Users\RUNNER~1\AppData\Local\Temp\junit13368809472936183425. The following paths could not be deleted (see suppressed exceptions for details): , outDir, outDir\opentest4j-1.2.0.pom

FetchTest > canFetchArtifactToSpecificDir(File) FAILED
    java.io.IOException at TempDirectory.java:262

Notice that this same test passes on Java 11 on MacOS and Linux, and on Java 17 on MacOS, Linux and Windows. It seems to fail very consistently on Java 11/Windows.

Steps to reproduce

It should be very easy to reproduce the problem as long as you can run your tests on the specific Windows and Java versions being used by GitHub Actions CI. The code under test will basically just copy a file from one location to another.

Feel free to fork my project to make it easy to run the tests.

GitHub Environment:

Current runner version: '2.286.0'
Operating System
  Microsoft Windows Server 2019
  10.0.17763
  Datacenter
Virtual Environment
  Environment: windows-2019
  Version: 20220110.1
  Included Software: https://github.com/actions/virtual-environments/blob/win19/20220110.1/images/win/Windows2019-Readme.md
  Image Release: https://github.com/actions/virtual-environments/releases/tag/win19%2F20220110.1

Java configuration:
  Distribution: zulu
  Version: 11.0.13+8
  Path: C:\hostedtoolcache\windows\Java_Zulu_jdk\11.0.13-8\x64

Context

  • Used versions (Jupiter/Vintage/Platform):
dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testImplementation 'org.assertj:assertj-core:3.21.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'

    intTestImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    intTestImplementation 'org.assertj:assertj-core:3.21.0'
    intTestRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}

Link to build file

  • Build Tool/IDE:

Gradle downloaded from (see the wrapper properties):

distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions