Issue 64 in peaberry: Equals on service proxy

3 views
Skip to first unread message

peab...@googlecode.com

unread,
Sep 26, 2011, 9:00:05 AM9/26/11
to guice...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 64 by js.cedar...@gmail.com: Equals on service proxy
http://code.google.com/p/peaberry/issues/detail?id=64

When I get a service proxy, equals returns false for every argument.


Foo foo = //injected with guice using service()
foo.equals(foo); //Returns false! I think this method call should return
true

peab...@googlecode.com

unread,
Sep 30, 2011, 5:13:43 PM9/30/11
to guice...@googlegroups.com

Comment #1 on issue 64 by mccu...@gmail.com: Equals on service proxy
http://code.google.com/p/peaberry/issues/detail?id=64

Getting equals right with proxies is a hard problem given that most equals
implementations don't support subclasses. Bloch discusses this in Effective
Java, see also
http://cwmaier.blogspot.com/2007/07/liskov-substitution-principle-equals.html

At the moment the service proxy just delegates to the actual service
implementation for equals/hashcode, so if your implementation of equals
works with subclasses then you should get the expected result. However if
your equals method checks against an exact class (ie. using getClass() ==
obj.getClass() rather than instanceof) then you will get negative results
as above.

Alternative approaches/suggestions are welcomed, feel free to attach a
patch for the ImportGlue proxy class.

peab...@googlecode.com

unread,
Oct 27, 2011, 6:02:43 AM10/27/11
to guice...@googlegroups.com

Comment #2 on issue 64 by js.cedar...@gmail.com: Equals on service proxy
http://code.google.com/p/peaberry/issues/detail?id=64

I don't understand the problem in detail. And I am very sure that it is
complicated.

But for me this seems to be obvious:

for
Foo foo =...

without any equals implementation
foo.equals(foo)

returns true.
This is the default implementation of equals() and should also work for
with proxies...


Every Java developer without deep knowledge of the proxy topic will expect
this behavior. So maybe a workaround could be useful in that case.


peab...@googlecode.com

unread,
Oct 27, 2011, 9:12:54 PM10/27/11
to guice...@googlegroups.com

Comment #3 on issue 64 by mccu...@gmail.com: Equals on service proxy
http://code.google.com/p/peaberry/issues/detail?id=64

Sure, the issue is that we delegate straight to the underlying object - so
if that has a correct substitutable implementation of equals then that will
behave correctly when proxied. The issue is when the object being proxied
uses the default implementation of equals or a non-substitutable version,
that's when you get the spurious result of !foo.equals(foo).

We should probably do a quick == test before delegating to the proxied
object, which would fix this case.

peab...@googlecode.com

unread,
Oct 27, 2011, 9:17:01 PM10/27/11
to guice...@googlegroups.com
Updates:
Status: Accepted

Comment #4 on issue 64 by mccu...@gmail.com: Equals on service proxy
http://code.google.com/p/peaberry/issues/detail?id=64

(No comment was entered for this change.)

peab...@googlecode.com

unread,
Oct 27, 2011, 9:21:07 PM10/27/11
to guice...@googlegroups.com
Updates:
Owner: mccu...@gmail.com

Comment #5 on issue 64 by mccu...@gmail.com: Equals on service proxy

peab...@googlecode.com

unread,
Jun 21, 2015, 9:47:43 PM6/21/15
to guice...@googlegroups.com
Updates:
Status: Duplicate

Comment #7 on issue 64 by mccu...@gmail.com: Equals on service proxy
https://code.google.com/p/peaberry/issues/detail?id=64

Moved to https://github.com/ops4j/peaberry/issues/67

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
Reply all
Reply to author
Forward
0 new messages