Skip to content

Allow InetAddressMatchers.builder().include(...) to be called in a fluent style #19071

@philwebb

Description

@philwebb

Expected Behavior

InetAddressMatchers.builder().includeAddresses(...) returns this for fluent style calls, however, calling includeAddresses again doesn't work in a useful way.

Current Behavior

InetAddressMatchers.builder().includeAddresses(...) accepts a list of include addresses and the javadoc states "Adds an include list matcher that permits only the specified addresses.". If you call InetAddressMatchers.builder().includeAddresses(List.of("192.168.1.1", "192.168.1.2")).build() you'll get a matcher that matcher "192.168.1.1" or 192.168.1.2".

If however, you call the method more than once, e.g. InetAddressMatchers.builder().includeAddresses(List.of("192.168.1.1")).includeAddresses(List.of("192.168.1.2")).build() you get a matcher that won't match anything. This is because internally there are two IncludeListInetAddressMatcher instances. One will only match 192.168.1.1 and the other will only match 192.168.1.2.

Context

This came up during the development of spring-projects/spring-boot#49687. You could argue that the API is working as designed, so perhaps this issue can just be closed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions