pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1651198 - in /pdfbox/trunk/pdfbox/src: main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java
Date Mon, 12 Jan 2015 21:13:21 GMT
Author: msahyoun
Date: Mon Jan 12 21:13:21 2015
New Revision: 1651198

URL: http://svn.apache.org/r1651198
Log:
PDFBOX-2516 don't return null for empty items

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java?rev=1651198&r1=1651197&r2=1651198&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
Mon Jan 12 21:13:21 2015
@@ -18,6 +18,7 @@ package org.apache.pdfbox.pdmodel.intera
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.pdfbox.cos.COSArray;
@@ -80,13 +81,16 @@ public final class PDRadioButton extends
         return getDictionary().getFlag(COSName.FF, FLAG_RADIOS_IN_UNISON);
     }
 
-    
     @Override
     public String getDefaultValue() throws IOException
     {
         COSBase attribute = getInheritableAttribute(COSName.DV);
 
-        if (attribute instanceof COSName)
+        if (attribute == null)
+        {
+            return "";
+        }
+        else if (attribute instanceof COSName)
         {
             return ((COSName) attribute).getName();
         }
@@ -164,7 +168,7 @@ public final class PDRadioButton extends
                 return options.get(idx);
             }
         }
-        return null;
+        return "";
     }
     
     /**
@@ -196,7 +200,7 @@ public final class PDRadioButton extends
         {
             return COSArrayList.convertCOSStringCOSArrayToList((COSArray)value);
         }
-        return new ArrayList<String>();
+        return Collections.<String>emptyList();
     } 
     
     /**
@@ -221,8 +225,12 @@ public final class PDRadioButton extends
     public String getValue() throws IOException
     {
         COSBase attribute = getInheritableAttribute(COSName.V);
-
-        if (attribute instanceof COSName)
+        
+        if (attribute == null)
+        {
+            return "";
+        }
+        else if (attribute instanceof COSName)
         {
             return ((COSName) attribute).getName();
         }

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java?rev=1651198&r1=1651197&r2=1651198&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java
Mon Jan 12 21:13:21 2015
@@ -81,6 +81,13 @@ public class TestRadioButtons extends Te
             PDAcroForm form = new PDAcroForm( doc );
             PDRadioButton radioButton = new PDRadioButton(form);
             
+            // test that there are no nulls returned for an empty field
+            // only specific methods are tested here
+            assertNotNull(radioButton.getDefaultValue());
+            assertNotNull(radioButton.getExportValue());
+            assertNotNull(radioButton.getOptions());
+            assertNotNull(radioButton.getValue());
+            
             // Test setting/getting option values - the dictionaries Opt entry
             List<String> options = new ArrayList<String>();
             options.add("Value01");



Mime
View raw message