You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2019/08/21 19:12:45 UTC

svn commit: r1865650 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Author: tilman
Date: Wed Aug 21 19:12:45 2019
New Revision: 1865650

URL: http://svn.apache.org/viewvc?rev=1865650&view=rev
Log:
PDFBOX-4071: SonarQube fix: refactor nested try-catch, silence false positive

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1865650&r1=1865649&r2=1865650&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Wed Aug 21 19:12:45 2019
@@ -977,21 +977,11 @@ public class PDDocument implements Close
     public static PDDocument load(File file, String password, InputStream keyStore, String alias,
                                   MemoryUsageSetting memUsageSetting) throws IOException
     {
+        @SuppressWarnings({"squid:S2095"}) // raFile not closed here, may be needed for signing
         RandomAccessBufferedFileInputStream raFile = new RandomAccessBufferedFileInputStream(file);
         try
         {
-            ScratchFile scratchFile = new ScratchFile(memUsageSetting);
-            try
-            {
-                PDFParser parser = new PDFParser(raFile, password, keyStore, alias, scratchFile);
-                parser.parse();
-                return parser.getPDDocument();
-            }
-            catch (IOException ioe)
-            {
-                IOUtils.closeQuietly(scratchFile);
-                throw ioe;
-            }
+            return load(raFile, password, keyStore, alias, memUsageSetting);
         }
         catch (IOException ioe)
         {
@@ -999,6 +989,24 @@ public class PDDocument implements Close
             throw ioe;
         }
     }
+
+    private static PDDocument load(RandomAccessBufferedFileInputStream raFile, String password,
+                                   InputStream keyStore, String alias,
+                                   MemoryUsageSetting memUsageSetting) throws IOException
+    {
+        ScratchFile scratchFile = new ScratchFile(memUsageSetting);
+        try
+        {
+            PDFParser parser = new PDFParser(raFile, password, keyStore, alias, scratchFile);
+            parser.parse();
+            return parser.getPDDocument();
+        }
+        catch (IOException ioe)
+        {
+            IOUtils.closeQuietly(scratchFile);
+            throw ioe;
+        }
+    }
 
     /**
      * Parses a PDF. The given input stream is copied to the memory to enable random access to the