From: Javen O'Neal Date: Sun, 17 Jul 2016 06:04:56 +0000 (+0000) Subject: throw exception if hyperlink is invalid type when validating hyperlink X-Git-Tag: REL_3_15_BETA3~106 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c0ee980ac79305f59e6a60847379805781116b1a;p=poi.git throw exception if hyperlink is invalid type when validating hyperlink git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753016 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java index b0c9a92f35..2d11272464 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java @@ -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); } }