From a56fb21721444995f35941058c5ee103116fe57a Mon Sep 17 00:00:00 2001 From: Tilman Hausherr Date: Thu, 31 Oct 2024 07:58:36 +0000 Subject: [PATCH] PDFBOX-5894: don't close prematurely, as suggested by Derek Wickern git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1921703 13f79535-47bb-0310-9956-ffa450edef68 --- pdfbox/src/main/java/org/apache/pdfbox/Loader.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/Loader.java b/pdfbox/src/main/java/org/apache/pdfbox/Loader.java index 32b8d788440..cae28ab1b95 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/Loader.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/Loader.java @@ -73,11 +73,19 @@ public static FDFDocument loadFDF(String filename) throws IOException */ public static FDFDocument loadFDF(File file) throws IOException { - try (RandomAccessRead readBuffer = new RandomAccessReadBufferedFile(file)) + RandomAccessRead raFile = null; + try { - FDFParser parser = new FDFParser(readBuffer); + // PDFBOX-5894: RandomAccessRead is not closed here + raFile = new RandomAccessReadBufferedFile(file); + FDFParser parser = new FDFParser(raFile); return parser.parse(); } + catch (IOException ioe) + { + IOUtils.closeQuietly(raFile); + throw ioe; + } } /**