pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1852574 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageTree.java
Date Thu, 31 Jan 2019 07:36:58 GMT
Author: tilman
Date: Thu Jan 31 07:36:58 2019
New Revision: 1852574

URL: http://svn.apache.org/viewvc?rev=1852574&view=rev
Log:
PDFBOX-4452: avoid ClassCastException

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageTree.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageTree.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageTree.java?rev=1852574&r1=1852573&r2=1852574&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageTree.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageTree.java Thu
Jan 31 07:36:58 2019
@@ -29,6 +29,8 @@ import org.apache.pdfbox.pdmodel.common.
 
 import java.util.ArrayList;
 import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * The page tree, which defines the ordering of pages in the document in an efficient manner.
@@ -37,6 +39,7 @@ import java.util.List;
  */
 public class PDPageTree implements COSObjectable, Iterable<PDPage>
 {
+    private static final Log LOG = LogFactory.getLog(PDPageTree.class);
     private final COSDictionary root;
     private final PDDocument document; // optional
 
@@ -132,7 +135,7 @@ public class PDPageTree implements COSOb
     {
         List<COSDictionary> result = new ArrayList<COSDictionary>();
 
-        COSArray kids = (COSArray)node.getDictionaryObject(COSName.KIDS);
+        COSArray kids = node.getCOSArray(COSName.KIDS);
         if (kids == null)
         {
             // probably a malformed PDF
@@ -141,7 +144,15 @@ public class PDPageTree implements COSOb
 
         for (int i = 0, size = kids.size(); i < size; i++)
         {
-            result.add((COSDictionary)kids.getObject(i));
+            COSBase base = kids.getObject(i);
+            if (base instanceof COSDictionary)
+            {
+                result.add((COSDictionary) base);
+            }
+            else
+            {
+                LOG.warn("COSDictionary expected, but got " + base.getClass().getSimpleName());
+            }
         }
 
         return result;



Mime
View raw message