Uploaded image for project: 'JGroups'
  1. JGroups
  2. JGRP-591

IpAddress.hashCode() not unique per ip/port

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Major Major
    • 2.4.2, 2.5.1, 2.6
    • 2.4.1 SP4
    • None

      Current implementation produces hashcode where ip/port combos "1.2.3.4:2" and "1.2.3.5:1" result in the same hash code.

      Existing code:
      public final int hashCode()

      { return ip_addr != null ? ip_addr.hashCode() + port : port; }

      Manual test code:
      InetAddress ip1 = InetAddress.getByAddress( new byte[]

      {1,2,3,4}

      );
      int port1 = 2;
      int hash1 = ip1.hashCode() + port1;
      System.out.println( "hash1 = " + hash1 );

      InetAddress ip2 = InetAddress.getByAddress( new byte[]

      {1,2,3,5}

      );
      int port2 = 1;
      int hash2 = ip2.hashCode() + port2;
      System.out.println( "hash2 = " + hash2 );

              rhn-engineering-bban Bela Ban
              rob_chou robert chou (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: