Bug in org.apache.commons.lang3.tuple.Pair

Alex Tsvetkov <[email protected]> Thu, 26 Sep 2024 12:49:50 +0300
Newsgroups gmane.comp.jakarta.commons.user
Message-ID <CAHdrJBVkZoLGAvnU2tZbsrq=qXBwwBCcXZou5cjqCAS-TYWJLA@mail.gmail.com>
Hi.

I found a bug in the implementation of the method `equals` of class `Pair`.

Implementation must be symmetric. Current implementation is not.

Her test showing the problem:

```

@Test
void run() {
    var pair = Pair.of("a", "b");
    var entry = new Map.Entry<String, String>() {
        public String getKey() { return "a"; }
        public String getValue() { return "b"; }
        public String setValue(String value) { return null; }
    };
    assertTrue(pair.equals(entry)); // true
    assertTrue(entry.equals(pair)); // false
}
```