Skip to content

File remains locked after using PdfReader #1517

@rodrigoschonardt

Description

@rodrigoschonardt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions