EqualShouldHandleNullArg

1 view
Skip to first unread message

Nidhi Rawal

unread,
Aug 11, 2007, 8:08:56 AM8/11/07
to mono-soc-2007
Description:
This rule checks if the overridden Equals (Object) method checks for
the null argument or not. It raises warning if it does not handle
null argument.

Examples:
1) public class EqualsChecksForNullArg
{
public override bool Equals(System.Object obj)
{
if (obj == null)
{
return false;
}
else
return this == obj;
}
public override int GetHashCode ()
{
return 1;
}
}
This is good.

2) public class DoesNotCheckForNullArg
{
public override bool Equals(System.Object obj)
{
return this == obj;
}
public override int GetHashCode ()
{
return 1;
}
}
This is bad.

Reference:
http://findbugs.sourceforge.net/bugDescriptions.html#NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT

Nidhi Rawal

unread,
Aug 13, 2007, 2:13:05 PM8/13/07
to mono-soc-2007
Reply all
Reply to author
Forward
0 new messages