You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Matt Benson <gu...@gmail.com> on 2010/09/21 00:16:50 UTC

[proxy] suppression of equals/hashCode

Hi all,
  By default, [proxy]'s provided ProxyFactory implementations all force their generated proxies to implement hashCode via System.identityHashCode() and equals via reference equality.  I will leave it to the original author to explain the reasons behind this design decision if he chooses, but I would propose that it would not be out of order to provide a means of allowing a user to implement these methods as any other.  If anyone has any opinions to contribute on the matter, please make them known.

-Matt
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [proxy] suppression of equals/hashCode

Posted by James Carman <ja...@carmanconsulting.com>.
On Tue, Sep 21, 2010 at 10:18 AM, Matt Benson <gu...@gmail.com> wrote:
>
> I had just had that thought this morning:  that in particular, only a delegating type proxy, an Interceptor proxy in [proxy] speak, would be subject to the condition James outline where an interceptor proxy and its target should *not* be considered equal.  Thanks for weighing in here, Joerg...
>

Also consider the delegating (again, proxy speak) proxy situation
where the target comes from a pool.  If we let the "target" respond to
equals/hashCode, then a proxy instance may not even be equal to
itself!

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [proxy] suppression of equals/hashCode

Posted by Matt Benson <gu...@gmail.com>.
On Sep 21, 2010, at 2:23 AM, Jörg Schaible wrote:

> Hi Matt and James,
> 
> Matt Benson wrote:
> 
>> 
>> On Sep 20, 2010, at 6:11 PM, James Carman wrote:
>> 
>>> On Mon, Sep 20, 2010 at 7:01 PM, Matt Benson <gu...@gmail.com>
>>> wrote:
>>>> 
>>>> This would seem quite complicated to execute, would it not?
>>>> 
>>> 
>>> What do you propose?
>>> 
>> 
>> I don't know for sure yet.  My initial reaction would have been to try and
>> consolidate the current handling somehow down to AbstractProxyFactory,
>> then control whether proxies used the default behavior with a simple
>> boolean property.  This would therefore be what it is today:  a detail of
>> the existing ProxyFactory implementations.
> 
> the standard invoker in ProxyToys does simply call the methods of the 
> proxied objects. However, it depends on the actual proxy type, if this 
> default is replaced with something else (e.g. all delegating proxies will 
> handle equal and hashCode differently).
> 
> Bottom line is that it depends on the proxies' purpose, but it is not 
> configurable. You have to create a new proxy type to overwrite the proxies' 
> standard behavior.
> 

I had just had that thought this morning:  that in particular, only a delegating type proxy, an Interceptor proxy in [proxy] speak, would be subject to the condition James outline where an interceptor proxy and its target should *not* be considered equal.  Thanks for weighing in here, Joerg...

> - Jörg
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [proxy] suppression of equals/hashCode

Posted by Jörg Schaible <jo...@gmx.de>.
Hi Matt and James,

Matt Benson wrote:

> 
> On Sep 20, 2010, at 6:11 PM, James Carman wrote:
> 
>> On Mon, Sep 20, 2010 at 7:01 PM, Matt Benson <gu...@gmail.com>
>> wrote:
>>> 
>>> This would seem quite complicated to execute, would it not?
>>> 
>> 
>> What do you propose?
>> 
> 
> I don't know for sure yet.  My initial reaction would have been to try and
> consolidate the current handling somehow down to AbstractProxyFactory,
> then control whether proxies used the default behavior with a simple
> boolean property.  This would therefore be what it is today:  a detail of
> the existing ProxyFactory implementations.

the standard invoker in ProxyToys does simply call the methods of the 
proxied objects. However, it depends on the actual proxy type, if this 
default is replaced with something else (e.g. all delegating proxies will 
handle equal and hashCode differently).

Bottom line is that it depends on the proxies' purpose, but it is not 
configurable. You have to create a new proxy type to overwrite the proxies' 
standard behavior.

- Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [proxy] suppression of equals/hashCode

Posted by Matt Benson <gu...@gmail.com>.
On Sep 20, 2010, at 6:11 PM, James Carman wrote:

> On Mon, Sep 20, 2010 at 7:01 PM, Matt Benson <gu...@gmail.com> wrote:
>> 
>> This would seem quite complicated to execute, would it not?
>> 
> 
> What do you propose?
> 

I don't know for sure yet.  My initial reaction would have been to try and consolidate the current handling somehow down to AbstractProxyFactory, then control whether proxies used the default behavior with a simple boolean property.  This would therefore be what it is today:  a detail of the existing ProxyFactory implementations.

-Matt

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [proxy] suppression of equals/hashCode

Posted by James Carman <ja...@carmanconsulting.com>.
On Mon, Sep 20, 2010 at 7:01 PM, Matt Benson <gu...@gmail.com> wrote:
>
> This would seem quite complicated to execute, would it not?
>

What do you propose?

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [proxy] suppression of equals/hashCode

Posted by Matt Benson <gu...@gmail.com>.
On Sep 20, 2010, at 5:26 PM, James Carman wrote:

> On Mon, Sep 20, 2010 at 6:16 PM, Matt Benson <gu...@gmail.com> wrote:
>> Hi all,
>>  By default, [proxy]'s provided ProxyFactory implementations all force their generated proxies to implement hashCode via System.identityHashCode() and equals via reference equality.  I will leave it to the original author to explain the reasons behind this design decision if he chooses, but I would propose that it would not be out of order to provide a means of allowing a user to implement these methods as any other.  If anyone has any opinions to contribute on the matter, please make them known.
>> 
> 
> As the original author, I do not recall the exact reasoning behind
> this decision at this time.  However, I would assume that it has
> something to do with the fact that you may have two different proxies
> with the same "target" object.  One of these proxies could have
> interceptors on it (for security, logging, whatever) and the other
> might not.  If you let the "target" respond to equals/hashCode, then
> these two proxies would be considered equal, when they clearly should
> not.
> 
> I agree that it would be nice to allow the user to override this
> behavior, but I think the general case should be to just use Object's
> implementation of these two methods.  I don't want to muddy up
> ProxyFactory's API to do this, though.  I'd rather figure out some
> other way to do this.  Perhaps we could make every proxy object
> implement some interface (ProxyObject perhaps).  That interface could
> have a "setter" on it to allow the user to override the "thing" that
> implements the equals/hashCode methods:
> 
> public interface Equalizer<T> {
>  public boolean equals(T source, T target);
>  public int hashCode(T source);
> }
> 

This would seem quite complicated to execute, would it not?

-Matt

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [proxy] suppression of equals/hashCode

Posted by James Carman <ja...@carmanconsulting.com>.
On Mon, Sep 20, 2010 at 6:16 PM, Matt Benson <gu...@gmail.com> wrote:
> Hi all,
>  By default, [proxy]'s provided ProxyFactory implementations all force their generated proxies to implement hashCode via System.identityHashCode() and equals via reference equality.  I will leave it to the original author to explain the reasons behind this design decision if he chooses, but I would propose that it would not be out of order to provide a means of allowing a user to implement these methods as any other.  If anyone has any opinions to contribute on the matter, please make them known.
>

As the original author, I do not recall the exact reasoning behind
this decision at this time.  However, I would assume that it has
something to do with the fact that you may have two different proxies
with the same "target" object.  One of these proxies could have
interceptors on it (for security, logging, whatever) and the other
might not.  If you let the "target" respond to equals/hashCode, then
these two proxies would be considered equal, when they clearly should
not.

I agree that it would be nice to allow the user to override this
behavior, but I think the general case should be to just use Object's
implementation of these two methods.  I don't want to muddy up
ProxyFactory's API to do this, though.  I'd rather figure out some
other way to do this.  Perhaps we could make every proxy object
implement some interface (ProxyObject perhaps).  That interface could
have a "setter" on it to allow the user to override the "thing" that
implements the equals/hashCode methods:

public interface Equalizer<T> {
  public boolean equals(T source, T target);
  public int hashCode(T source);
}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org