Skip to content

Fix Java Network.compareAddress to compare the IPv6 scope id (#5696)#5771

Merged
bernardnormier merged 2 commits into
zeroc-ice:mainfrom
bernardnormier:fix-java-compareaddress-scopeid
Jun 30, 2026
Merged

Fix Java Network.compareAddress to compare the IPv6 scope id (#5696)#5771
bernardnormier merged 2 commits into
zeroc-ice:mainfrom
bernardnormier:fix-java-compareaddress-scopeid

Conversation

@bernardnormier

Copy link
Copy Markdown
Member

Network.compareAddress compared only the raw 16 address bytes returned by InetAddress.getAddress(), which omits the IPv6 scope id. As a result two IPv6 link-local addresses that differ only by their zone (e.g. fe80::1%eth0 vs fe80::1%eth1) compared as equal under compareAddress, even though InetAddress.equals (used for connection reuse) treats them as distinct — a compareTo/equals contract inconsistency in IPEndpointI.compareTo.

This now also compares Inet6Address.getScopeId() when both operands are IPv6, mirroring the C++ sin6_scope_id fix in #5679 (same comment).

Fixes #5696.

🤖 Generated with Claude Code

…ce#5696)

compareAddress compared only the raw 16 address bytes, so two IPv6
link-local addresses differing only by their zone (e.g. fe80::1%eth0 vs
fe80::1%eth1) sorted as equal even though InetAddress.equals reports them
as distinct. Compare Inet6Address.getScopeId() as well, mirroring the C++
sin6_scope_id fix (zeroc-ice#5679), so compareTo is consistent with equals.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 29, 2026 17:43
@bernardnormier bernardnormier requested a review from pepone June 29, 2026 17:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

This PR fixes Network.compareAddress in the Java Ice runtime so that two IPv6 addresses differing only by their scope id (zone), such as fe80::1%eth0 and fe80::1%eth1, are no longer treated as equal. Previously only the raw 16 address bytes from InetAddress.getAddress() were compared, omitting the scope id and creating a compareTo/equals contract inconsistency in IPEndpointI.compareTo.

Changes:

  • Capture the InetAddress operands and compare their raw address bytes as before.
  • When both operands are Inet6Address, additionally compare getScopeId() to distinguish scoped link-local addresses.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@bernardnormier bernardnormier merged commit d616214 into zeroc-ice:main Jun 30, 2026
45 of 46 checks passed
pepone pushed a commit that referenced this pull request Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java: Network.compareAddress ignores the IPv6 scope id

3 participants