diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-04-24 03:31:10 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-04-27 05:43:07 +0200 |
commit | 9ee976823dfc18e7ba5cf885b92032504b060ed9 (patch) | |
tree | f37eff642be7f8aca29fd14df07377b2488d283b /app/src/main/java/com/wireguard/config/IPCidr.java | |
parent | 254cc4cc8787745df0e153eba3357cdb6a4b9226 (diff) |
Throw IllegalArgumentExceptions when arguments are bad
This will make the two way data binding crash more, but it will improve
the robustness of the config file parser, which deals with exceptions
gracefully, and when we move to one way data binding, it will help with
that too.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/config/IPCidr.java')
-rw-r--r-- | app/src/main/java/com/wireguard/config/IPCidr.java | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/app/src/main/java/com/wireguard/config/IPCidr.java b/app/src/main/java/com/wireguard/config/IPCidr.java index adc778c0..245141ac 100644 --- a/app/src/main/java/com/wireguard/config/IPCidr.java +++ b/app/src/main/java/com/wireguard/config/IPCidr.java @@ -25,11 +25,11 @@ public class IPCidr implements Parcelable { } }; - public IPCidr(String in) throws UnknownHostException { + public IPCidr(String in) { parse(in); } - private void parse(String in) throws UnknownHostException { + private void parse(String in) { cidr = -1; int slash = in.lastIndexOf('/'); if (slash != -1 && slash < in.length() - 1) { @@ -39,7 +39,11 @@ public class IPCidr implements Parcelable { } catch (Exception e) { } } - address = InetAddress.getByName(in); + try { + address = InetAddress.getByName(in); + } catch (UnknownHostException e) { + throw new IllegalArgumentException(e); + } if ((address instanceof Inet6Address) && (cidr > 128 || cidr < 0)) cidr = 128; else if ((address instanceof Inet4Address) && (cidr > 32 || cidr < 0)) |