You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2018/03/29 10:52:16 UTC

svn commit: r1827975 - in /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox: io/IOUtils.java multipdf/PDFMergerUtility.java

Author: msahyoun
Date: Thu Mar 29 10:52:15 2018
New Revision: 1827975

URL: http://svn.apache.org/viewvc?rev=1827975&view=rev
Log:
PDFBOX-4158: don't throw exception in finally clause

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/IOUtils.java
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/IOUtils.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/IOUtils.java?rev=1827975&r1=1827974&r2=1827975&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/IOUtils.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/io/IOUtils.java Thu Mar 29 10:52:15 2018
@@ -142,10 +142,6 @@ public final class IOUtils
             {
                 return ioe;
             }
-            else
-            {
-                return null;
-            }
         }
         return null;
     }

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java?rev=1827975&r1=1827974&r2=1827975&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java Thu Mar 29 10:52:15 2018
@@ -263,8 +263,6 @@ public class PDFMergerUtility
             // - all FileInputStreams are closed
             // - there's a way to see which errors occured
 
-            IOException firstException = null;
-
             List<PDDocument> tobeclosed = new ArrayList<PDDocument>();
 
             try
@@ -291,47 +289,30 @@ public class PDFMergerUtility
                     destination.getDocumentCatalog().setMetadata(destinationMetadata);
                 }
                 
-                try 
+                if (destinationStream == null)
+                {
+                    destination.save(destinationFileName);
+                }
+                else
                 {
-                    if (destinationStream == null)
-                    {
-                        destination.save(destinationFileName);
-                    }
-                    else
-                    {
-                        destination.save(destinationStream);
-                    }
-                }
-                catch (IOException ioe)
-                {
-                    LOG.warn("Couldn't save destination", ioe);
-                    if (firstException == null)
-                    {
-                        firstException = ioe;
-                    }
+                    destination.save(destinationStream);
                 }
             }
             finally
             {
                 if (destination != null)
                 {
-                    firstException = IOUtils.closeAndLogException(destination, LOG, "PDDocument", firstException);
+                    IOUtils.closeAndLogException(destination, LOG, "PDDocument", null);
                 }
 
                 for (PDDocument doc : tobeclosed)
                 {
-                    firstException = IOUtils.closeAndLogException(doc, LOG, "PDDocument", firstException);
+                    IOUtils.closeAndLogException(doc, LOG, "PDDocument", null);
                 }
 
                 for (FileInputStream stream : fileInputStreams)
                 {
-                    firstException = IOUtils.closeAndLogException(stream, LOG, "FileInputStream", firstException);
-                }
-
-                // rethrow first exception to keep method contract
-                if (firstException != null)
-                {
-                    throw firstException;
+                    IOUtils.closeAndLogException(stream, LOG, "FileInputStream", null);
                 }
             }
         }