coobird / thumbnailator

Thumbnailator - a thumbnail generation library for Java
MIT License
5.14k stars 784 forks source link

Thumbnails.of() do not close output file on v0.4.9 #148

Closed Nick-IV closed 4 years ago

Nick-IV commented 4 years ago

My test-cases was failed after moving on v0.4.9. Rollback on v0.4.8 restore functionality.

Here is simple test which allow to reproduce the issue:

@Test
public void failure() throws IOException {
    File tmpDir = new File(System.getProperty("user.dir") + "\\target\\tmp");
    String sourceDirString = System.getProperty("user.dir") + "\\src\\test\\resources";
    File dscfJpg = new File(sourceDirString,"DSCF0001.JPG");

    // @Before
    if(!tmpDir.exists()) {
        tmpDir.mkdirs();
    }
    // @Before

    Thumbnails.of( new FileInputStream(dscfJpg) )
            .size(500, 500)
            .toFile( new File(tmpDir.getAbsolutePath(), "toJpeg.jpg") );

    // @After
    if(tmpDir.exists()) {
        FileUtils.deleteDirectory(tmpDir);
    }
    // @After
}

In result: java.io.IOException: Unable to delete file: D:{cut}\target\tmp\toJpeg.jpg File stay locked while java process works. If I will call several Thumbnails.of() in a row just last one will be locked.

Windows 10 1607 LTSC OpenJDK 11.0.1

coobird commented 4 years ago

Thank you for the report. I haven't reproduced the issue, but I did find the part that I suspect is causing this. I'll look into this very soon.

coobird commented 4 years ago

This is likely to be an issue in Windows environments, since I've experienced a similar issue in the past with an input or output stream being left open. (I can't reproduce it in Linux.) A fix is in the pipeline, and I expect to get it out this weekend.

msrcn commented 7 months ago

I also encountered the same problem in v0.4.9 on Windows, but it did not occur in v0.4.8

coobird commented 7 months ago

@aoleiliyanuobuendiya This issue was resolved in 0.4.10. The current version is 0.4.20. If this issue is still present in 0.4.20, please feel free to file a new issue with more details. Thank you!