summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-12-11 02:28:34 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2018-12-11 02:28:34 +0100
commitb729aad1c001620f279328171aff565a5ff63e1d (patch)
treeb28166b4cf938d0a75fc5ad82f84c0cda89cd350 /app/src/main/java/com/wireguard
parent15aa724b1ddae80c9df4fa09cd770841747d7787 (diff)
Throw illegalargumentexception instead of nullpointerexception for builder errors
Diffstat (limited to 'app/src/main/java/com/wireguard')
-rw-r--r--app/src/main/java/com/wireguard/config/Config.java4
-rw-r--r--app/src/main/java/com/wireguard/config/Interface.java5
-rw-r--r--app/src/main/java/com/wireguard/config/Peer.java4
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;
}
/**