From 6caf61a70647a901a4c2e7521c99c2fc39a3f571 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Wed, 2 Apr 2014 13:34:37 +0200 Subject: fix #3716: NPE in getCachedMissingFromSearch --- main/src/cgeo/geocaching/DataStore.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'main/src/cgeo/geocaching/DataStore.java') diff --git a/main/src/cgeo/geocaching/DataStore.java b/main/src/cgeo/geocaching/DataStore.java index a822b5d..f627d7d 100644 --- a/main/src/cgeo/geocaching/DataStore.java +++ b/main/src/cgeo/geocaching/DataStore.java @@ -3044,28 +3044,25 @@ public class DataStore { // get cached CacheListActivity final Set cachedGeocodes = new HashSet(); - for (Tile tile : tiles) { + for (final Tile tile : tiles) { cachedGeocodes.addAll(cacheCache.getInViewport(tile.getViewport(), CacheType.ALL)); } // remove found in search result cachedGeocodes.removeAll(searchResult.getGeocodes()); // check remaining against viewports - Set missingFromSearch = new HashSet(); - for (String geocode : cachedGeocodes) { + final Set missingFromSearch = new HashSet(); + for (final String geocode : cachedGeocodes) { if (connector.canHandle(geocode)) { - Geocache geocache = cacheCache.getCacheFromCache(geocode); - if (geocache.getCoordZoomLevel() <= maxZoom) { - boolean found = false; - for (Tile tile : tiles) { + final Geocache geocache = cacheCache.getCacheFromCache(geocode); + // TODO: parallel searches seem to have the potential to make some caches be expunged from the CacheCache (see issue #3716). + if (geocache != null && geocache.getCoordZoomLevel() <= maxZoom) { + for (final Tile tile : tiles) { if (tile.containsPoint(geocache)) { - found = true; + missingFromSearch.add(geocode); break; } } - if (found) { - missingFromSearch.add(geocode); - } } } } -- cgit v1.1