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 2020/01/25 12:09:58 UTC

svn commit: r1873146 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java

Author: tilman
Date: Sat Jan 25 12:09:57 2020
New Revision: 1873146

URL: http://svn.apache.org/viewvc?rev=1873146&view=rev
Log:
PDFBOX-4071: simplify code

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java?rev=1873146&r1=1873145&r2=1873146&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java Sat Jan 25 12:09:57 2020
@@ -390,51 +390,52 @@ public class COSDocument extends COSBase
     /**
      * This will close all storage and delete the tmp files.
      *
-     *  @throws IOException If there is an error close resources.
+     * @throws IOException If there is an error close resources.
      */
     @Override
     public void close() throws IOException
     {
-        if (!closed)
+        if (closed)
         {
-            // Make sure that:
-            // - first Exception is kept
-            // - all COSStreams are closed
-            // - ScratchFile is closed
-            // - there's a way to see which errors occurred
+            return;
+        }
 
-            IOException firstException = null;
+        // Make sure that:
+        // - first Exception is kept
+        // - all COSStreams are closed
+        // - ScratchFile is closed
+        // - there's a way to see which errors occurred
+        IOException firstException = null;
 
-            // close all open I/O streams
-            for (COSObject object : objectPool.values())
+        // close all open I/O streams
+        for (COSObject object : objectPool.values())
+        {
+            if (!object.isObjectNull())
             {
-                if (!object.isObjectNull())
+                COSBase cosObject = object.getObject();
+                if (cosObject instanceof COSStream)
                 {
-                    COSBase cosObject = object.getObject();
-                    if (cosObject instanceof COSStream)
-                    {
-                        firstException = IOUtils.closeAndLogException((COSStream) cosObject, LOG,
-                                "COSStream", firstException);
-                    }
+                    firstException = IOUtils.closeAndLogException((COSStream) cosObject, LOG,
+                            "COSStream", firstException);
                 }
             }
+        }
 
-            for (COSStream stream : streams)
-            {
-                firstException = IOUtils.closeAndLogException(stream, LOG, "COSStream", firstException);
-            }
+        for (COSStream stream : streams)
+        {
+            firstException = IOUtils.closeAndLogException(stream, LOG, "COSStream", firstException);
+        }
 
-            if (scratchFile != null)
-            {
-                firstException = IOUtils.closeAndLogException(scratchFile, LOG, "ScratchFile", firstException);
-            }
-            closed = true;
+        if (scratchFile != null)
+        {
+            firstException = IOUtils.closeAndLogException(scratchFile, LOG, "ScratchFile", firstException);
+        }
+        closed = true;
 
-            // rethrow first exception to keep method contract
-            if (firstException != null)
-            {
-                throw firstException;
-            }
+        // rethrow first exception to keep method contract
+        if (firstException != null)
+        {
+            throw firstException;
         }
     }