If the 'other' instance is also a proxy, then both proxies will by definition be
equal, as they will always resolve to the same underlying bean (as they are both being
accessed by the same thread, that will have the same contexts active).
Anything we specify here is going to break the transitive behaviour of equals, consider we
have a proxy A and normal class instantiated with new B.
The normal class B has absolutely no knowledge of proxies, so will always compare the
proxy instances fields directly, if we have the proxy forwarding the equals call to the
underlying bean then you may end up with a situation where A.equals(B) is true, but
B.equals(A) is false.
HashCode has similar problems, if the proxy forwards it to the underlying bean, then the
hash code will change as the underlying bean changes.
I think we should specify that non-portable behaviour results, and tell people not to put
proxies into a HashMap.
Stuart
On 19/10/2011, at 4:17 AM, Mark Struberg wrote:
Hi folks!
There is a problem still in the chain which is a bit more trickier. It's about
equals() on contextual references.
If the 'other' instance which gets compared with is a proxy as well, then we
would first need to 'unpack' it and pass the underlying contextual instance into
the comparison implementation. Otherwise accessing private fields from the 'other'
will actually only hit the proxy, and not the 'real' target.
But otherwise it should work fine.
Wdyt?
1.) Should we specify this?
2.) What is the expected behaviour?
3.) Do we like to specify equals() for beans at all?
4.) Is there some established behaviour in other frameworks which heavily uses proxies?
5.) Should we at least specify that 'non portable behaviour results'?
LieGrue,
strub
----- Original Message -----
> From: Pete Muir <pmuir(a)redhat.com>
> To: Mark Struberg <struberg(a)yahoo.de>
> Cc: cdi-dev(a)lists.jboss.org; Stuart Douglas <sdouglas(a)redhat.com>
> Sent: Monday, March 14, 2011 12:52 PM
> Subject: Re: [cdi-dev] calling 'equals' on a proxy?
>
> Stuart, you had this one worked out right? I believe the spec says the behaviour
> is unspecified.
>
> On 7 Mar 2011, at 15:52, Mark Struberg wrote:
>
>> Hi Pete, others!
>>
>> Do you remember our discussion about what should happen if equals() gets
> called on a proxy?
>>
>> Should it route to the equals method of the currently proxied instance?
>>
>> LieGrue,
>> strub
>>
>>
>>
>> _______________________________________________
>> cdi-dev mailing list
>> cdi-dev(a)lists.jboss.org
>>
https://lists.jboss.org/mailman/listinfo/cdi-dev
>
_______________________________________________
cdi-dev mailing list
cdi-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/cdi-dev