From c3bb46490031f6d778c608d7d1755a9cf10c05ca Mon Sep 17 00:00:00 2001 From: Tilman Hausherr Date: Thu, 31 Oct 2024 08:16:55 +0000 Subject: [PATCH] PDFBOX-5894: add test git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1921708 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/pdfbox/pdmodel/TestFDF.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java index 292bf68210f..7fd6eebb633 100644 --- a/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java +++ b/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java @@ -16,8 +16,6 @@ */ package org.apache.pdfbox.pdmodel; -import static org.junit.jupiter.api.Assertions.assertEquals; - import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -26,9 +24,15 @@ import java.util.List; import org.apache.pdfbox.Loader; +import org.apache.pdfbox.cos.COSBase; +import org.apache.pdfbox.cos.COSDictionary; +import org.apache.pdfbox.cos.COSName; +import org.apache.pdfbox.cos.COSObject; import org.apache.pdfbox.pdmodel.fdf.FDFDocument; import org.apache.pdfbox.pdmodel.fdf.FDFField; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; + +import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; /** @@ -54,6 +58,26 @@ void testLoad2() throws URISyntaxException, IOException checkFields("/org/apache/pdfbox/pdfparser/nocatalog.fdf"); } + /** + * PDFBOX-5894: check that premature file close bug is fixed. + * + * @throws IOException + */ + @Test + void testPDFBox5894() throws IOException + { + try (FDFDocument fdf = Loader.loadFDF(new File("target/pdfs/PDFBOX-5894.fdf"))) + { + List objectsByType = fdf.getDocument().getObjectsByType(COSName.ANNOT); + assertEquals(4, objectsByType.size()); + for (COSObject obj : objectsByType) + { + COSBase base = obj.getObject(); + assertEquals(COSName.ANNOT, ((COSDictionary) base).getDictionaryObject(COSName.TYPE)); + } + } + } + private void checkFields(String name) throws IOException, URISyntaxException { try (FDFDocument fdf = Loader.loadFDF(new File(TestFDF.class.getResource(name).toURI())))