Author: tilman
Date: Fri Mar 27 14:19:30 2026
New Revision: 1932593

Log:
PDFBOX-5660: sonar fix

Modified:
   
pdfbox/branches/3.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java
   
pdfbox/branches/3.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature2.java

Modified: 
pdfbox/branches/3.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java
==============================================================================
--- 
pdfbox/branches/3.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java
 Fri Mar 27 12:10:03 2026        (r1932592)
+++ 
pdfbox/branches/3.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature.java
 Fri Mar 27 14:19:30 2026        (r1932593)
@@ -348,14 +348,16 @@ public class CreateVisibleSignature exte
                 doc.saveIncremental(fos);
             }
         }
-        
-        // Do not close signatureOptions before saving, because some COSStream 
objects within
-        // are transferred to the signed document.
-        // Do not allow signatureOptions get out of scope before saving, 
because then the COSDocument
-        // in signature options might by closed by gc, which would close 
COSStream objects prematurely.
-        // See https://issues.apache.org/jira/browse/PDFBOX-3743
-        IOUtils.closeQuietly(signatureOptions);
-        IOUtils.closeQuietly(doc);
+        finally
+        {        
+            // Do not close signatureOptions before saving, because some 
COSStream objects within
+            // are transferred to the signed document.
+            // Do not allow signatureOptions get out of scope before saving, 
because then the COSDocument
+            // in signature options might by closed by gc, which would close 
COSStream objects prematurely.
+            // See https://issues.apache.org/jira/browse/PDFBOX-3743
+            IOUtils.closeQuietly(signatureOptions);
+            IOUtils.closeQuietly(doc);
+        }
     }
 
     // Find an existing signature (assumed to be empty). You will usually not 
need this.

Modified: 
pdfbox/branches/3.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature2.java
==============================================================================
--- 
pdfbox/branches/3.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature2.java
        Fri Mar 27 12:10:03 2026        (r1932592)
+++ 
pdfbox/branches/3.0/examples/src/main/java/org/apache/pdfbox/examples/signature/CreateVisibleSignature2.java
        Fri Mar 27 14:19:30 2026        (r1932593)
@@ -163,7 +163,7 @@ public class CreateVisibleSignature2 ext
 
         // creating output document and prepare the IO streams.
 
-        SignatureOptions signatureOptions = new SignatureOptions();
+        SignatureOptions signatureOptions = null;
         try (FileOutputStream fos = new FileOutputStream(signedFile);
                 PDDocument doc = Loader.loadPDF(inputFile))
         {
@@ -297,13 +297,15 @@ public class CreateVisibleSignature2 ext
                 doc.saveIncremental(fos);
             }
         }
-        
-        // Do not close signatureOptions before saving, because some COSStream 
objects within
-        // are transferred to the signed document.
-        // Do not allow signatureOptions get out of scope before saving, 
because then the COSDocument
-        // in signature options might by closed by gc, which would close 
COSStream objects prematurely.
-        // See https://issues.apache.org/jira/browse/PDFBOX-3743
-        IOUtils.closeQuietly(signatureOptions);
+        finally
+        {        
+            // Do not close signatureOptions before saving, because some 
COSStream objects within
+            // are transferred to the signed document.
+            // Do not allow signatureOptions get out of scope before saving, 
because then the COSDocument
+            // in signature options might by closed by gc, which would close 
COSStream objects prematurely.
+            // See https://issues.apache.org/jira/browse/PDFBOX-3743
+            IOUtils.closeQuietly(signatureOptions);
+        }
     }
 
     private PDRectangle createSignatureRectangle(PDDocument doc, Rectangle2D 
humanRect)

Reply via email to