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:32 UTC
svn commit: r1827976 - in
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: io/IOUtils.java
multipdf/PDFMergerUtility.java
Author: msahyoun
Date: Thu Mar 29 10:52:32 2018
New Revision: 1827976
URL: http://svn.apache.org/viewvc?rev=1827976&view=rev
Log:
PDFBOX-4158: don't throw exception in finally clause
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/IOUtils.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/IOUtils.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/IOUtils.java?rev=1827976&r1=1827975&r2=1827976&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/IOUtils.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/io/IOUtils.java Thu Mar 29 10:52:32 2018
@@ -149,10 +149,6 @@ public final class IOUtils
{
return ioe;
}
- else
- {
- return null;
- }
}
return null;
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java?rev=1827976&r1=1827975&r2=1827976&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java Thu Mar 29 10:52:32 2018
@@ -278,8 +278,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<>();
MemoryUsageSetting partitionedMemSetting = memUsageSetting != null ?
memUsageSetting.getPartitionedCopy(sources.size()+1) :
@@ -288,16 +286,7 @@ public class PDFMergerUtility
{
for (InputStream sourceInputStream : sources)
{
- PDDocument sourceDoc = null;
- try
- {
- sourceDoc = PDDocument.load(sourceInputStream, partitionedMemSetting);
- }
- catch (IOException ioe)
- {
- LOG.error("Couldn't load source document", ioe);
- firstException = ioe;
- }
+ PDDocument sourceDoc = PDDocument.load(sourceInputStream, partitionedMemSetting);
tobeclosed.add(sourceDoc);
appendDocument(destination, sourceDoc);
}
@@ -312,42 +301,25 @@ 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
{
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);
}
}
}