aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2012-04-12 18:18:16 +0200
committerSamuel Tardieu <sam@rfc1149.net>2012-04-12 18:20:42 +0200
commit925f3f6177d81de33cb231ac2afb91138df04cbb (patch)
tree8c87475d875a216119fa8842cb384c9dd640da76
parent948c8b87c8e264f32eac98e1d300305abcf54adc (diff)
downloadcgeo-925f3f6177d81de33cb231ac2afb91138df04cbb.zip
cgeo-925f3f6177d81de33cb231ac2afb91138df04cbb.tar.gz
cgeo-925f3f6177d81de33cb231ac2afb91138df04cbb.tar.bz2
Partial fix: do not crash if a cache has no coordinates
It looks like from time to time some caches are sent with null coordinates, at least when browsing the live map. This change prevents a NullPointerException from being thrown and logs this as an error in the log. This issue still needs to be addressed, as the root cause of the problem is yet unknown.
-rw-r--r--main/src/cgeo/geocaching/CacheCache.java18
1 files changed, 12 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/CacheCache.java b/main/src/cgeo/geocaching/CacheCache.java
index daee9ed..1ebb47f 100644
--- a/main/src/cgeo/geocaching/CacheCache.java
+++ b/main/src/cgeo/geocaching/CacheCache.java
@@ -6,6 +6,7 @@ import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.geopoint.Viewport;
import cgeo.geocaching.utils.LeastRecentlyUsedMap;
import cgeo.geocaching.utils.LeastRecentlyUsedMap.RemoveHandler;
+import cgeo.geocaching.utils.Log;
import org.apache.commons.lang3.StringUtils;
@@ -85,12 +86,17 @@ public class CacheCache {
}
public Set<String> getInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cacheType) {
- Set<String> geocodes = new HashSet<String>();
- for (cgCache cache : cachesCache.values()) {
- if (Viewport.isCacheInViewPort(centerLat.intValue(), centerLon.intValue(), spanLat.intValue(), spanLon.intValue(), cache.getCoords())) {
- if (CacheType.ALL == cacheType || cache.getType() == cacheType) {
- geocodes.add(cache.getGeocode());
- }
+ final Set<String> geocodes = new HashSet<String>();
+ for (final cgCache cache : cachesCache.values()) {
+ if (cache.getCoords() == null) {
+ // FIXME: this kludge must be removed, it is only present to help us debug the cases where
+ // caches contain null coordinates.
+ Log.e(Settings.tag, "CacheCache.getInViewport: got cache with null coordinates: " + cache.getGeocode());
+ continue;
+ }
+ if ((CacheType.ALL == cacheType || cache.getType() == cacheType) &&
+ Viewport.isCacheInViewPort(centerLat.intValue(), centerLon.intValue(), spanLat.intValue(), spanLon.intValue(), cache.getCoords())) {
+ geocodes.add(cache.getGeocode());
}
}
return geocodes;