4

The following is a part source code of org.apache.commons.lang3.builder.EqualsBuilder. What is the difference between pair and swappedPair ? why not swappedPair = Pair.of(pair.getRight(), pair.getLeft());

    static Pair<IDKey, IDKey> getRegisterPair(final Object lhs, final Object rhs) {
        final IDKey left = new IDKey(lhs);
        final IDKey right = new IDKey(rhs);
        return Pair.of(left, right);
    }

    /**
     * <p>
     * Returns <code>true</code> if the registry contains the given object pair.
     * Used by the reflection methods to avoid infinite loops.
     * Objects might be swapped therefore a check is needed if the object pair
     * is registered in given or swapped order.
     * </p>
     *
     * @param lhs <code>this</code> object to lookup in registry
     * @param rhs the other object to lookup on registry
     * @return boolean <code>true</code> if the registry contains the given object.
     * @since 3.0
     */
    static boolean isRegistered(final Object lhs, final Object rhs) {
        final Set<Pair<IDKey, IDKey>> registry = getRegistry();
        final Pair<IDKey, IDKey> pair = getRegisterPair(lhs, rhs);
        final Pair<IDKey, IDKey> swappedPair = Pair.of(pair.getLeft(), pair.getRight());

        return registry != null
                && (registry.contains(pair) || registry.contains(swappedPair));
    }
tkruse
  • 10,222
  • 7
  • 53
  • 80
devin
  • 41
  • 4
  • This almost seems like a bug. – Jason Aug 10 '17 at 02:37
  • 2
    In fact I'm almost certain it's a bug. – Jason Aug 10 '17 at 02:41
  • 2
    Good catch, it must be a bug indeed. Have raised it against the current GitHub repository. Depending on the merge of [apache/commons-lang#282](https://github.com/apache/commons-lang/pull/282) it should be fixed in the coming releases. – Naman Aug 10 '17 at 03:39

0 Answers0