On Thu, 26 Sept 2024 at 14:52, Gary Gregory <garydgreg...@gmail.com> wrote:
>
> Sebb,
>
> Pair _is_ a Map.Entry.

I get it now, sorry for all the noise.

As you wrote at the start, the examples are not valid Map.Entry
instances, so their behaviour is not guaranteed.

It's not sufficient to satisfy the compiler.
The implementation must also satisfy the Map.Entry contract.

> Gary
>
> On Thu, Sep 26, 2024, 9:46 AM sebb <seb...@gmail.com> wrote:
>
> > On Thu, 26 Sept 2024 at 14:33, Gary D. Gregory <ggreg...@apache.org>
> > wrote:
> > >
> > > Andrea,
> > >
> > > The relevant contract is
> > https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Map.Entry.html#equals(java.lang.Object)
> >
> > Which says "Returns true if the given object is also a map entry and ..."
> >
> > Also any class that overrides Object equals must be symmetric (and
> > transitive etc).
> >
> > Note that Map.Entry#equals returns false when compared against Pair;
> > it is compliant, even though it omits to repeat the Object contract in
> > its Javadoc.
> >
> > It is Pair#equals that gets it wrong.
> >
> > > Gary
> > >
> > > On 2024/09/26 12:45:07 Andrea Spinelli wrote:
> > > > IMHO, a Pair should not be equal to anything which is not a Pair.
> > > >
> > > > Reading the contract for equals
> > > >
> > > >
> > https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Object.html#equals(java.lang.Object)
> > > >
> > > >
> > > > it must be symmetric, so Pair.equals should return false if the
> > argument is a MapEntry
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > ________________________________
> > > > Da: Dávid Szigecsán <sige...@gmail.com>
> > > > Inviato: giovedì 26 settembre 2024 13:36
> > > > A: Commons Users List <user@commons.apache.org>
> > > > Oggetto: Re: Bug in org.apache.commons.lang3.tuple.Pair
> > > >
> > > > Hi,
> > > > As I see the "problem".
> > > > Pair.equal() returns true if the other entity is not an instance of
> > Pair.
> > > > In this case it is a Map.Entry.
> > > > Map.Entry.equals() howewer checks if the other is an instance of the
> > same
> > > > class. So if we want them to be equals, we should change the Map.Entry,
> > > > that is out of our limit of power. To make it symmetric we could check
> > for
> > > > the instances of the same class also (and return false in this case),
> > but I
> > > > think we don't want this.
> > > >
> > > > Dávid
> > > >
> > > > Alex Tsvetkov <a.e.tsvet...@gmail.com> ezt írta (időpont: 2024.
> > szept. 26.,
> > > > Cs 13:11):
> > > >
> > > > > 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
> > > > > }
> > > > > ```
> > > > >
> > > >
> > > > --
> > > > Il messaggio è stato analizzato da Libraesva ESG.
> > > > Seguire il link qui sotto per segnalarlo eventualmente come spam:
> > > > http://antispam01.imteam.it/action/4XDs5M0fYhzKmXJ/report-as-bad
> > > > Seguire il link qui sotto per mettere in blocklist il mittente:
> > > > http://antispam01.imteam.it/action/4XDs5M0fYhzKmXJ/blocklist
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> > > For additional commands, e-mail: user-h...@commons.apache.org
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> > For additional commands, e-mail: user-h...@commons.apache.org
> >
> >

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org

Reply via email to