Add getRequiredAddress() and getMaskBits() to IpAddressMatcher.java #16794
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes gh-16693
gh-16693
When reviewing the issue, the original request was to add a toString() method to IpAddressMatcher.
However, what the reporter actually needed was the hostAddress that had been set in the IpAddressMatcher.
I didn’t think it was appropriate to override toString() just to return the hostAddress, because toString() should ideally reflect the entire object state or be used for debugging purposes—not to expose a specific internal value. So I decided not to implement it that way.
As for getRequiredAddress(), I believed that it was sufficient to return the raw InetAddress directly without wrapping or transforming it to a hostAddress. This way, users can still access what they need without inconvenience.
On the other hand, since getMaskBits() is tightly coupled with the subnet concept and is inherently derived from the original hostAddress, I felt it was appropriate to expose that detail explicitly through this method.