From commits-return-12317-archive-asf-public=cust-asf.ponee.io@pdfbox.apache.org Tue Mar 27 11:20:55 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id A6D9C18064E for ; Tue, 27 Mar 2018 11:20:54 +0200 (CEST) Received: (qmail 70431 invoked by uid 500); 27 Mar 2018 09:20:53 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 70422 invoked by uid 99); 27 Mar 2018 09:20:53 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Mar 2018 09:20:53 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 1EC0C3A00A1 for ; Tue, 27 Mar 2018 09:20:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1827818 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java Date: Tue, 27 Mar 2018 09:20:53 -0000 To: commits@pdfbox.apache.org From: msahyoun@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20180327092053.1EC0C3A00A1@svn01-us-west.apache.org> Author: msahyoun Date: Tue Mar 27 09:20:52 2018 New Revision: 1827818 URL: http://svn.apache.org/viewvc?rev=1827818&view=rev Log: PDFBOX-4158: try closing all open IO ressources even if there is an error when closing one of these Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java?rev=1827818&r1=1827817&r2=1827818&view=diff ============================================================================== --- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java (original) +++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java Tue Mar 27 09:20:52 2018 @@ -427,24 +427,75 @@ public class COSDocument extends COSBase { if (!closed) { + // Make sure that: + // - first Exception is kept + // - all COSStreams are closed + // - ScratchFile is closed + // - there's a way to see which errors occured + + IOException firstException = null; + // close all open I/O streams for (COSObject object : getObjects()) { COSBase cosObject = object.getObject(); if (cosObject instanceof COSStream) { - ((COSStream) cosObject).close(); + COSStream cosStream = (COSStream) cosObject; + try + { + cosStream.close(); + } + catch (IOException ioe) + { + LOG.warn("Error closing COSStream", ioe); + if (firstException == null) + { + firstException = ioe; + } + + } } } for (COSStream stream : streams) { - stream.close(); + try + { + stream.close(); + } + catch (IOException ioe) + { + LOG.warn("Error closing COSStream", ioe); + if (firstException == null) + { + firstException = ioe; + } + + } } if (scratchFile != null) { - scratchFile.close(); + try + { + scratchFile.close(); + } + catch (IOException ioe) + { + LOG.warn("Error closing ScratchFile", ioe); + if (firstException == null) + { + firstException = ioe; + } + + } } closed = true; + + // rethrow first exception to keep method contract + if (firstException != null) + { + throw firstException; + } } }