pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1810594 - in /pdfbox/trunk/pdfbox/src: main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionURI.java test/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionURITest.java
Date Mon, 02 Oct 2017 20:33:40 GMT
Author: tilman
Date: Mon Oct  2 20:33:40 2017
New Revision: 1810594

URL: http://svn.apache.org/viewvc?rev=1810594&view=rev
Log:
PDFBOX-3946: avoid NPE if URI doesn't exist

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionURI.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionURITest.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionURI.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionURI.java?rev=1810594&r1=1810593&r2=1810594&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionURI.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionURI.java
Mon Oct  2 20:33:40 2017
@@ -16,6 +16,7 @@
  */
 package org.apache.pdfbox.pdmodel.interactive.action;
 
+import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSString;
@@ -57,11 +58,16 @@ public class PDActionURI extends PDActio
      * This will get the uniform resource identifier to resolve. It should be encoded in
7-bit
      * ASCII, but UTF-8 is supported too.
      *
-     * @return The URI entry of the specific URI action dictionary.
+     * @return The URI entry of the specific URI action dictionary or null if there isn't
any.
      */
     public String getURI()
     {
-        return new String(((COSString) action.getDictionaryObject(COSName.URI)).getBytes(),
Charsets.UTF_8);
+        COSBase base = action.getDictionaryObject(COSName.URI);
+        if (base instanceof COSString)
+        {
+            return new String(((COSString) base).getBytes(), Charsets.UTF_8);
+        }
+        return null;
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionURITest.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionURITest.java?rev=1810594&r1=1810593&r2=1810594&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionURITest.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionURITest.java
Mon Oct  2 20:33:40 2017
@@ -16,6 +16,7 @@
 package org.apache.pdfbox.pdmodel.interactive.action;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 import org.junit.Test;
 
 /**
@@ -31,6 +32,7 @@ public class PDActionURITest
     public void testUTF8URI()
     {
         PDActionURI actionURI = new PDActionURI();
+        assertNull(actionURI.getURI());
         actionURI.setURI("http://組匶替綎.com/");
         assertEquals("http://経営承継.com/", actionURI.getURI());
     }



Mime
View raw message