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/src/main/java/com/wireguard/config/Peer.java | |
parent | c1ba1f409cd1566cb11d0c26d610ffdff4d2e24c (diff) |
Throw illegalargumentexception instead of nullpointerexception for builder errors
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/config/Peer.java')
-rw-r--r-- | app/src/main/java/com/wireguard/config/Peer.java | 4 |
1 files changed, 3 insertions, 1 deletions
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; } /** |