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>
This commit is contained in:
Jason A. Donenfeld
2018-04-27 05:43:07 +02:00
parent 254cc4cc87
commit 9ee976823d
4 changed files with 35 additions and 37 deletions
@@ -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))