Skip to content

Unresolved IPv6 InetSocketAddress serialized without brackets, losing port on round-trip #6185

Description

@pjfanning

(reported by @renechoi in #6125 — fix to be implemented independently as the original PR was closed without a CLA)

InetSocketAddressSerializer writes values as host + ":" + port. For a resolved address it takes the host part from InetAddress.toString() and brackets IPv6 literals, so output looks like "[2001:db8::1]:443". For an unresolved address there is no InetAddress, so it falls back to getHostName() and writes an IPv6 literal bare:

InetSocketAddress.createUnresolved("2001:db8::1", 443)
// serialized as "2001:db8::1:443"

The trailing :443 is indistinguishable from another hextet, so the port cannot be recovered on deserialization.

This has become more visible since #5951: deserialization now always constructs unresolved addresses via InetSocketAddress.createUnresolved(), so a bare IPv6 address value read by Jackson no longer survives a round-trip — on re-serialization the port gets appended bare, and the next read absorbs it into the host name.

Expected: the unresolved branch should bracket IPv6 literals the same way the resolved branch already does, e.g. "[2001:db8::1]:443". Host names that are already bracketed (which is what the deserializer stores for "[...]:port" input) must not be bracketed twice.

Applies to 2.x (2.18+) and 3.x; existing JDKTypeSerializationTest.testInetSocketAddress() covers the unresolved form only for IPv4 and host names.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions