aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2014-04-01 23:21:45 +0200
committerSamuel Tardieu <sam@rfc1149.net>2014-04-02 00:16:32 +0200
commita045c6edaebe4200835aeffcea977fc8245b6ad1 (patch)
treefc23b56231eb9cd41d89ceb5c8663077f509fe8b /main/src
parenteee8074a6ff153987727292c32193853834b9c88 (diff)
downloadcgeo-a045c6edaebe4200835aeffcea977fc8245b6ad1.zip
cgeo-a045c6edaebe4200835aeffcea977fc8245b6ad1.tar.gz
cgeo-a045c6edaebe4200835aeffcea977fc8245b6ad1.tar.bz2
fix #3721: NPE in Geocache.hashCode()
Also, hash codes must be equal when the objects compare equal. Since equality compares only geocodes, the hash codes must also only take geocodes into consideration.
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/Geocache.java11
1 files changed, 3 insertions, 8 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index a03f515..a224e4e 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -1414,19 +1414,14 @@ public class Geocache implements ICache, IWaypoint {
@Override
public int hashCode() {
- return geocode.hashCode() * name.hashCode();
+ return StringUtils.defaultString(geocode).hashCode();
}
@Override
public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof Geocache)) {
- return false;
- }
+ // TODO: explain the following line or remove this non-standard equality method
// just compare the geocode even if that is not what "equals" normally does
- return StringUtils.isNotBlank(geocode) && geocode.equals(((Geocache) obj).geocode);
+ return this == obj || (obj instanceof Geocache && StringUtils.isNotEmpty(geocode) && geocode.equals(((Geocache) obj).geocode));
}
public void store(CancellableHandler handler) {