Opening a file with `PdfReader` (or `RandomAccessFileOrArray`) keeps the file locked after `close()`
christianGen opened this issue · comments
PLEASE FILL THIS TEMPLATE AS MUCH AS POSSIBLE. REMOVE IRRELEVANT PARTS.
Describe the bug
When opening a file using PdfReader
or RandomAccessFileOrArray
the file stays locked after having called close()
.
Windows, Java 21, OpenPDF 1.4.2 or 2.0.2.
To Reproduce
https://github.com/christianGen/openpdf_bug
Calling the junit test fails.
The relevant code:
try (RandomAccessFileOrArray ignored = new RandomAccessFileOrArray(filename)) {
// Don't do anything.
}
Files.move(Paths.get(filename), Paths.get(newFilename));
Files.move
will fail:
C:\Temp\openpdf_bug9650214420994590135\hello-in.pdf -> C:\Temp\openpdf_bug9650214420994590135\hello-out.pdf: Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird
java.nio.file.FileSystemException: C:\Temp\openpdf_bug9650214420994590135\hello-in.pdf -> C:\Temp\openpdf_bug9650214420994590135\hello-out.pdf: Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird
at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92)
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:414)
at java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:291)
at java.base/java.nio.file.Files.move(Files.java:1430)
at bug.Main.moveFile(Main.java:20)
Expected behavior
Calling close()
should release the resource.
System
(please complete the following information)
- OS: Windows 10 Enterprise 22H2
- OpenPDF version: 1.4.2 or 2.0.2
Your real name
Christian Loitsch
Duplicate of #1112