-
Notifications
You must be signed in to change notification settings - Fork 696
File remains locked after using PdfReader #1517
Copy link
Copy link
Open
Labels
Description
Describe the bug
When using the PdfReader(String filename) constructor, the underlying file handle is not properly released after closing the reader, causing the file to remain locked for the duration of the program execution. For now i was able to solve it by using a FileInputStream directly and closing it afterwards.
To Reproduce
import org.openpdf.text.pdf.PdfReader;
import java.io.FileInputStream;
public class Test {
public static void main(String[] args) throws Exception {
try (PdfReader reader = new PdfReader( "C:\\Users\\ras\\Documents\\teste.pdf" )) {
// nothing really needed
}
// workaround
// try (FileInputStream fis = new FileInputStream("C:\\Users\\ras\\Documents\\teste.pdf");
// PdfReader reader = new PdfReader(fis)) {
// }
// file is locked during execution of the program
Thread.sleep( 50000 );
}
}Expected behavior
For PdfReader constructors that receive and manage file references internally, the file must be completely released when the reader is closed. For cases where the stream is user-managed, the existing behavior of not closing the stream can be preserved.
System
- OS: Windows
- OpenPDF version: 3.0.3
Your real name
Rodrigo Schonardt
Reactions are currently unavailable