pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1688687 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java
Date Wed, 01 Jul 2015 16:49:13 GMT
Author: msahyoun
Date: Wed Jul  1 16:49:13 2015
New Revision: 1688687

URL: http://svn.apache.org/r1688687
Log:
PDFBOX-2849: avoid potential ClassCastException for incorrect dictionary entries

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java?rev=1688687&r1=1688686&r2=1688687&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java
Wed Jul  1 16:49:13 2015
@@ -22,6 +22,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
@@ -92,8 +93,17 @@ public final class PDCheckbox extends PD
      */
     public String getValue()
     {
-        COSName value = (COSName) getInheritableAttribute(COSName.V);
-        return value == null ? "" : value.getName();
+        // the dictionary shall be a name object but it might not be
+        // so don't assume it is.
+        COSBase value = getInheritableAttribute(COSName.V);
+        if (value instanceof COSName)
+        {
+            return ((COSName)value).getName();
+        }
+        else
+        {
+            return "";
+        }
     }
 
     /**
@@ -103,8 +113,17 @@ public final class PDCheckbox extends PD
      */
     public String getDefaultValue()
     {
-        COSName value = (COSName) getInheritableAttribute(COSName.DV);
-        return value == null ? "" : value.getName();
+        // the dictionary shall be a name object but it might not be
+        // so don't assume it is.
+        COSBase value = getInheritableAttribute(COSName.DV);
+        if (value instanceof COSName)
+        {
+            return ((COSName)value).getName();
+        }
+        else
+        {
+            return "";
+        }
     }
 
     @Override



Mime
View raw message