1
0
mirror of synced 2026-08-23 02:27:44 +00:00

Align Null Behavior

Previously, ExternalInetAddressMatcher treated a null InetAddress
as external by negating InternalInetAddressMatcher's result.

This commit makes ExternalInetAddressMatcher return false for a
null address, so that neither the internal nor the external
matcher classifies an unknown address as a match.

Signed-off-by: Josh Cummings <3627351+jzheaux@users.noreply.github.com>
This commit is contained in:
Josh Cummings
2026-07-11 21:12:25 -06:00
parent b6b9d743a0
commit c9220ca39e
2 changed files with 9 additions and 0 deletions
@@ -335,6 +335,9 @@ public final class InetAddressMatchers {
@Override
public boolean matches(@Nullable InetAddress address) {
if (address == null) {
return false;
}
return !this.internalMatcher.matches(address);
}
@@ -415,6 +415,12 @@ class InetAddressMatchersTests {
@Nested
class ExternalInetAddressMatcherTests {
@Test
void matchesWhenInetAddressNullThenReturnsFalse() {
InetAddressMatcher matcher = InetAddressMatchers.matchExternal().build();
assertThat(matcher.matches((InetAddress) null)).isFalse();
}
@ParameterizedTest
@ValueSource(strings = { "8.8.8.8", "1.1.1.1" })
void matchesWhenIpv4PublicThenReturnsTrue(String address) throws Exception {