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 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 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; } /**