Fixes a (possible) NullPointerException.

This commit is contained in:
lubomir.marinov 2015-02-08 14:02:17 +00:00
parent 50dd346aaf
commit 5e489a8f05

View File

@ -290,36 +290,42 @@ public abstract class Candidate<T extends Candidate<?>>
public boolean equals(Object obj) public boolean equals(Object obj)
throws NullPointerException throws NullPointerException
{ {
if(obj == this) if (obj == this)
return true; return true;
if( ! (obj instanceof Candidate)) if (! (obj instanceof Candidate))
return false; return false;
Candidate<?> targetCandidate = (Candidate<?>) obj; Candidate<?> candidate = (Candidate<?>) obj;
//compare candidate addresses //compare candidate addresses
if( ! targetCandidate.getTransportAddress() if (! candidate.getTransportAddress().equals(getTransportAddress()))
.equals(getTransportAddress()))
return false; return false;
//compare bases //compare bases
if( getBase() == null ) Candidate<?> base = getBase();
Candidate<?> candidateBase = candidate.getBase();
boolean baseEqualsCandidateBase;
if (base == null)
{ {
if (targetCandidate.getBase() != null) if (candidateBase != null)
return false; return false;
else
baseEqualsCandidateBase = true;
}
else
{
baseEqualsCandidateBase = base.equals(candidateBase);
} }
//compare other properties //compare other properties
if(((getBase() == this && targetCandidate.getBase() == targetCandidate) return
|| getBase().equals(targetCandidate.getBase())) (baseEqualsCandidateBase
&& getPriority() == targetCandidate.getPriority() || (base == this && candidateBase == candidate))
&& getType() == targetCandidate.getType() && getPriority() == candidate.getPriority()
&& getFoundation().equals(targetCandidate.getFoundation())) && getType() == candidate.getType()
{ && getFoundation().equals(candidate.getFoundation());
return true;
}
return false;
} }
/** /**