I am interested in some thoughts on how valid our implementation of equals is on our
SimplePrincipal.
The javadoc for Principal described the requirements of the equals method as: -
anonymous wrote : Compares this principal to the specified object. Returns true if the
object passed in matches the principal represented by the implementation of this
interface.
To me I think our equals method goes too far. I should be able to implement my own
Principal which contains additional information that I want to be included in an equality
check but if the equals method of SimplePrincipal is called it is going to claim they are
equal even though they are not.
So we could have a situation where SimplePrincipal.equals(OtherPrincipal) returns true
when OtherPrincipal.equals(SimplePrinicpal) returns false.
| public boolean equals(Object another)
| {
| if (!(another instanceof Principal))
| return false;
| String anotherName = ((Principal) another).getName();
| boolean equals = false;
| if (name == null)
| equals = anotherName == null;
| else
| equals = name.equals(anotherName);
| return equals;
| }
|
Looking at other Principal implementation Sun seem to have the same interpretation as me
as well, here is their description of their equals method for their KerberosPrincipal
implementation: -
anonymous wrote : Compares the specified Object with this Principal for equality. Returns
true if the given object is also a KerberosPrincipal and the two KerberosPrincipal
instances are equivalent. More formally two KerberosPrincipal instances are equal if the
values returned by getName() are equal and the values returned by getNameType() are
equal.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4076265#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...