]> source.dussan.org Git - poi.git/commitdiff
throw exception if hyperlink is invalid type when validating hyperlink
authorJaven O'Neal <onealj@apache.org>
Sun, 17 Jul 2016 06:04:56 +0000 (06:04 +0000)
committerJaven O'Neal <onealj@apache.org>
Sun, 17 Jul 2016 06:04:56 +0000 (06:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753016 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java

index b0c9a92f35bc70b0b846593c7c223b860cf6d75c..2d1127246431d6be8b484175c5e43f6839d0f882 100644 (file)
@@ -235,20 +235,26 @@ public class XSSFHyperlink implements Hyperlink {
         }
     }
 
+    @SuppressWarnings("fall-through")
     private void validate(String address) {
-        switch (_type){
+        switch (_type) {
             // email, path to file and url must be valid URIs
             case Hyperlink.LINK_EMAIL:
             case Hyperlink.LINK_FILE:
             case Hyperlink.LINK_URL:
                 try {
                     new URI(address);
-                } catch (URISyntaxException x) {
-                    IllegalArgumentException y = new IllegalArgumentException("Address of hyperlink must be a valid URI");
-                    y.initCause(x);
-                    throw y;
+                } catch (URISyntaxException e) {
+                    throw new IllegalArgumentException("Address of hyperlink must be a valid URI", e);
                 }
                 break;
+            case Hyperlink.LINK_DOCUMENT:
+                // currently not evaluating anything.
+                break;
+            default:
+                // this check wouldn't need to be done if _type was checked when object was set
+                // since _type is final, this check would only need to be done once
+                throw new IllegalStateException("Invalid Hyperlink type: " + _type);
         }
     }