diff options
Diffstat (limited to 'app/src/main/java/com/wireguard/config')
-rw-r--r-- | app/src/main/java/com/wireguard/config/Config.java | 6 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/config/Interface.java | 7 | ||||
-rw-r--r-- | app/src/main/java/com/wireguard/config/Peer.java | 6 |
3 files changed, 9 insertions, 10 deletions
diff --git a/app/src/main/java/com/wireguard/config/Config.java b/app/src/main/java/com/wireguard/config/Config.java index 7b9bcab3..d2c1395f 100644 --- a/app/src/main/java/com/wireguard/config/Config.java +++ b/app/src/main/java/com/wireguard/config/Config.java @@ -30,9 +30,7 @@ public final class Config { private final List<Peer> peers; private Config(final Builder builder) { - if (builder.interfaze == null) - throw new IllegalArgumentException("An [Interface] section is required"); - interfaze = builder.interfaze; + interfaze = Objects.requireNonNull(builder.interfaze, "An [Interface] section is required"); // Defensively copy to ensure immutability even if the Builder is reused. peers = Collections.unmodifiableList(new ArrayList<>(builder.peers)); } @@ -189,6 +187,8 @@ public final class Config { } public Config build() { + if (interfaze == null) + throw new IllegalArgumentException("An [Interface] section is required"); return new Config(this); } diff --git a/app/src/main/java/com/wireguard/config/Interface.java b/app/src/main/java/com/wireguard/config/Interface.java index f97c4731..da30fbcc 100644 --- a/app/src/main/java/com/wireguard/config/Interface.java +++ b/app/src/main/java/com/wireguard/config/Interface.java @@ -44,14 +44,11 @@ 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 = builder.keyPair; + keyPair = Objects.requireNonNull(builder.keyPair, "Interfaces must have a private key"); listenPort = builder.listenPort; mtu = builder.mtu; } @@ -264,6 +261,8 @@ public final class Interface { } public Interface build() { + if (keyPair == null) + throw new IllegalArgumentException("Interfaces must have a private key"); return new Interface(this); } diff --git a/app/src/main/java/com/wireguard/config/Peer.java b/app/src/main/java/com/wireguard/config/Peer.java index 1eb30197..1250fcb3 100644 --- a/app/src/main/java/com/wireguard/config/Peer.java +++ b/app/src/main/java/com/wireguard/config/Peer.java @@ -35,14 +35,12 @@ 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 = builder.publicKey; + publicKey = Objects.requireNonNull(builder.publicKey, "Peers must have a public key"); } /** @@ -226,6 +224,8 @@ public final class Peer { } public Peer build() { + if (publicKey == null) + throw new IllegalArgumentException("Peers must have a public key"); return new Peer(this); } |