OpenPDF is a free Java library for creating and editing PDF files, with a LGPL and MPL open source license. OpenPDF is based on a fork of iText. We welcome contributions from other developers. Please feel free to submit pull-requests and bugreports to this GitHub repository.
Other
3.6k
stars
596
forks
source link
Opening a file with `PdfReader` (or `RandomAccessFileOrArray`) keeps the file locked after `close()` #1187
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)
PLEASE FILL THIS TEMPLATE AS MUCH AS POSSIBLE. REMOVE IRRELEVANT PARTS.
Describe the bug
When opening a file using
PdfReader
orRandomAccessFileOrArray
the file stays locked after having calledclose()
.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:
Files.move
will fail:Expected behavior
Calling
close()
should release the resource.System
(please complete the following information)
Your real name
Christian Loitsch