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/10/20 15:08:34 UTC

svn commit: r1882703 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java

Author: tilman
Date: Tue Oct 20 15:08:33 2020
New Revision: 1882703

URL: http://svn.apache.org/viewvc?rev=1882703&view=rev
Log:
PDFBOX-4997: treat non-COSUpdateInfo objects as isNeedToBeUpdated == false, as suggested by Michael Klink

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=1882703&r1=1882702&r2=1882703&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Tue Oct 20 15:08:33 2020
@@ -521,8 +521,7 @@ public class COSWriter implements ICOSVi
                 cosBase = keyObject.get(cosObjectKey);
             }
             if (actual != null && objectKeys.containsKey(actual) 
-                    && object instanceof COSUpdateInfo && !((COSUpdateInfo)object).isNeedToBeUpdated() 
-                    && cosBase instanceof COSUpdateInfo && !((COSUpdateInfo)cosBase).isNeedToBeUpdated() )
+                    && !isNeedToBeUpdated(object) && !isNeedToBeUpdated(cosBase))
             {
                 return;
             }
@@ -536,6 +535,20 @@ public class COSWriter implements ICOSVi
     }
 
     /**
+     * Convenience method, so that we get false for types that can't be updated.
+     * @param base
+     * @return 
+     */
+    private boolean isNeedToBeUpdated(COSBase base)
+    {
+        if (base instanceof COSUpdateInfo)
+        {
+            return ((COSUpdateInfo) base).isNeedToBeUpdated();
+        }
+        return false;
+    }
+
+    /**
      * This will write a COS object.
      *
      * @param obj The object to write.