public static int compareObjectIdentity()

in src/main/java/com/amazonaws/encryptionsdk/internal/Utils.java [65:93]


  public static int compareObjectIdentity(Object a, Object b) {
    if (a == b) {
      return 0;
    }

    if (a == null) {
      return -1;
    }

    if (b == null) {
      return 1;
    }

    int hashCompare = Integer.compare(System.identityHashCode(a), System.identityHashCode(b));
    if (hashCompare != 0) {
      return hashCompare;
    }

    // Unfortunately these objects have identical hashcodes, so we need to find some other way to
    // compare them.
    // We'll do this by mapping them to an incrementing counter, and comparing their assigned IDs
    // instead.
    int fallbackCompare = Long.compare(getFallbackObjectId(a), getFallbackObjectId(b));
    if (fallbackCompare == 0) {
      throw new AssertionError("Failed to assign unique order to objects");
    }

    return fallbackCompare;
  }