Skip to content

EthernetAddress(long) retains bits outside the documented address range #149

Open

Description

@PHJ2000

The EthernetAddress(long) constructor documents that the address consists of the lowest six bytes, but retains all 64 bits. Two objects can therefore have identical string/byte representations while comparing unequal.

EthernetAddress address = new EthernetAddress(0x00010123456789abL);
EthernetAddress canonical = new EthernetAddress("01:23:45:67:89:ab");
address.toString().equals(canonical.toString()); // true
address.equals(canonical); // false
address.toLong(); // 0x00010123456789ab, including the extra high bit

EthernetAddress.valueOf(-1L) also fails an equality round trip through either its string or byte representation.

Expected: ignore the upper 16 bits as documented, keeping toLong, equality, hash codes, ordering and round trips consistent with the other constructors.

Reproduced on main, commit e489314 (JDK 21).

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions