diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-12-11 02:28:34 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-12-11 02:28:34 +0100 |
commit | 266ee7626c4c602c6f690c7c663526e38141986b (patch) | |
tree | b28166b4cf938d0a75fc5ad82f84c0cda89cd350 /app | |
parent | c1ba1f409cd1566cb11d0c26d610ffdff4d2e24c (diff) |
Throw illegalargumentexception instead of nullpointerexception for builder errors
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/com/wireguard/config/Config.java | 4 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/config/Interface.java | 5 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/config/Peer.java | 4 |
3 files changed, 10 insertions, 3 deletions
diff --git a/app/src/main/java/com/wireguard/config/Config.java b/app/src/main/java/com/wireguard/config/Config.java index 6c9d7ba3..7b9bcab3 100644 --- a/app/src/main/java/com/wireguard/config/Config.java +++ b/app/src/main/java/com/wireguard/config/Config.java @@ -30,7 +30,9 @@ public final class Config { private final List<Peer> peers; private Config(final Builder builder) { - interfaze = Objects.requireNonNull(builder.interfaze, "An [Interface] section is required"); + if (builder.interfaze == null) + throw new IllegalArgumentException("An [Interface] section is required"); + interfaze = builder.interfaze; // Defensively copy to ensure immutability even if the Builder is reused. peers = Collections.unmodifiableList(new ArrayList<>(builder.peers)); } diff --git a/app/src/main/java/com/wireguard/config/Interface.java b/app/src/main/java/com/wireguard/config/Interface.java index 7b114a09..f97c4731 100644 --- a/app/src/main/java/com/wireguard/config/Interface.java +++ b/app/src/main/java/com/wireguard/config/Interface.java @@ -44,11 +44,14 @@ public final class Interface { private final Optional<Integer> mtu; private Interface(final Builder builder) { + if (builder.keyPair == null) + throw new IllegalArgumentException("Interfaces must have a private key"); + // Defensively copy to ensure immutability even if the Builder is reused. addresses = Collections.unmodifiableSet(new LinkedHashSet<>(builder.addresses)); dnsServers = Collections.unmodifiableSet(new LinkedHashSet<>(builder.dnsServers)); excludedApplications = Collections.unmodifiableSet(new LinkedHashSet<>(builder.excludedApplications)); - keyPair = Objects.requireNonNull(builder.keyPair, "Interfaces must have a private key"); + keyPair = builder.keyPair; listenPort = builder.listenPort; mtu = builder.mtu; } diff --git a/app/src/main/java/com/wireguard/config/Peer.java b/app/src/main/java/com/wireguard/config/Peer.java index c15d3ae9..1eb30197 100644 --- a/app/src/main/java/com/wireguard/config/Peer.java +++ b/app/src/main/java/com/wireguard/config/Peer.java @@ -35,12 +35,14 @@ public final class Peer { private final Key publicKey; private Peer(final Builder builder) { + if (builder.publicKey == null) + throw new IllegalArgumentException("Peers must have a public key"); // Defensively copy to ensure immutability even if the Builder is reused. allowedIps = Collections.unmodifiableSet(new LinkedHashSet<>(builder.allowedIps)); endpoint = builder.endpoint; persistentKeepalive = builder.persistentKeepalive; preSharedKey = builder.preSharedKey; - publicKey = Objects.requireNonNull(builder.publicKey, "Peers must have a public key"); + publicKey = builder.publicKey; } /** |