Wednesday, 11 September 2013

Java string.equals(string) not behaving as expected

Java string.equals(string) not behaving as expected

I am getting the occasional odd result from String.equals(String).
here is the code:
boolean equals(OutputHolder other){
boolean result=true;
if( ! this.speciesEng.equals(other.speciesEng))
result=false;
else if( ! this.date.equals(other.date))
result=false;
else if( ! this.gridRef.equals(other.gridRef))
result=false;
else if( ! this.recorder.equals(other.recorder))
result=false;
return result;
}
All pretty straight forward but on some objects .equals() returns false on
what appear to be 2 identical strings.
This is a screenshot of the Expressions watchlist when the error occurs.
As you can see this.speciesEng.equals(other.speciesEng) is returning false
despite the fact that both strings appear the same.
The strings are initially from the same string resource but both have
passed over an XMPP connection and back.
I am at a loss as to how to proceed with debugging the problem. Any help
or suggestions welcome.

No comments:

Post a Comment