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
Link for test-cases is:
http://mono-soc-2007.googlecode.com/svn/trunk/nidhi/rules/Gendarme.Rules.BadPractice/Test/EqualShouldHandleNullArgTest.cs
> Reference:http://findbugs.sourceforge.net/bugDescriptions.html#NP_EQUALS_SHOULD...