diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2011-11-16 18:55:52 +0100 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2011-11-16 18:55:52 +0100 |
commit | 21bf94937ab7e021536a2b07d42a637230cd4d15 (patch) | |
tree | a4fa244bffb38a870a6bc50211b77522b98c48aa /main/src/cgeo/geocaching | |
parent | 7c12a456371070dbbc8fdd8c8c883234cc74160d (diff) | |
download | cgeo-21bf94937ab7e021536a2b07d42a637230cd4d15.zip cgeo-21bf94937ab7e021536a2b07d42a637230cd4d15.tar.gz cgeo-21bf94937ab7e021536a2b07d42a637230cd4d15.tar.bz2 |
Prevent null check warnings
The use of CollectionsUtils.isNotEmpty() is not detected as meaning
that the checked value is not null. Those calls have been inlined.
Also, at some other places, we know that a value cannot be null
but the compiler has no means to check it by itself because
this information is not conveyed in the method signatures.
Diffstat (limited to 'main/src/cgeo/geocaching')
-rw-r--r-- | main/src/cgeo/geocaching/cgBase.java | 6 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeocaches.java | 51 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/gcvote/GCVote.java | 3 |
3 files changed, 31 insertions, 29 deletions
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index 2c0c946..405ef58 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -2366,10 +2366,10 @@ public class cgBase { "ctl00$ContentBody$LogBookPanel1$LogButton", "Submit Log Entry", "ctl00$ContentBody$uxVistOtherListingGC", ""); putViewstates(params, viewstates); - if (CollectionUtils.isNotEmpty(trackables)) { // we have some trackables to proceed + if (trackables != null && !trackables.isEmpty()) { // we have some trackables to proceed final StringBuilder hdnSelected = new StringBuilder(); - for (cgTrackableLog tb : trackables) { + for (final cgTrackableLog tb : trackables) { if (tb.action != LogTypeTrackable.DO_NOTHING) { hdnSelected.append(Integer.toString(tb.id)); hdnSelected.append(tb.action.action); @@ -2419,7 +2419,7 @@ public class cgBase { params.put("ctl00$ContentBody$LogBookPanel1$btnConfirm", "Yes"); params.put("ctl00$ContentBody$LogBookPanel1$uxLogInfo", logInfo); params.put("ctl00$ContentBody$uxVistOtherListingGC", ""); - if (CollectionUtils.isNotEmpty(trackables)) { // we have some trackables to proceed + if (trackables != null && !trackables.isEmpty()) { // we have some trackables to proceed final StringBuilder hdnSelected = new StringBuilder(); for (cgTrackableLog tb : trackables) { diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index ad03f4b..54ba9dc 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -551,7 +551,7 @@ public class cgeocaches extends AbstractListActivity { setTitle("caches"); // get parameters - Bundle extras = getIntent().getExtras(); + final Bundle extras = getIntent().getExtras(); if (extras != null) { Object typeObject = extras.get(EXTRAS_LIST_TYPE); type = (typeObject instanceof CacheListType) ? (CacheListType) typeObject : CacheListType.OFFLINE; @@ -673,7 +673,7 @@ public class cgeocaches extends AbstractListActivity { title = res.getString(R.string.map_map); setTitle(title); showProgress(true); - search = (cgSearch) extras.get("search"); + search = extras != null ? (cgSearch) extras.get("search") : null; loadCachesHandler.sendMessage(Message.obtain()); break; default: @@ -1198,18 +1198,9 @@ public class cgeocaches extends AbstractListActivity { Log.w(Settings.tag, "cgeocaches.onContextItemSelected: " + e.toString()); } - // the context menu may be invoked for the cache or for the filter list - int touchedPos = -1; - cgCache cache = null; - if (adapterInfo != null) { - touchedPos = adapterInfo.position; - if (touchedPos < adapter.getCount()) { - cache = adapter.getItem(touchedPos); - } - } - if (id == MENU_COMPASS) { - Intent navigateIntent = new Intent(this, cgeonavigate.class); + final Intent navigateIntent = new Intent(this, cgeonavigate.class); + final cgCache cache = getCacheFromAdapter(adapterInfo); navigateIntent.putExtra("latitude", cache.getCoords().getLatitude()); navigateIntent.putExtra("longitude", cache.getCoords().getLongitude()); navigateIntent.putExtra("geocode", cache.getGeocode().toUpperCase()); @@ -1219,9 +1210,10 @@ public class cgeocaches extends AbstractListActivity { return true; } else if (id == MENU_LOG_VISIT) { - return cache.logVisit(this); + return getCacheFromAdapter(adapterInfo).logVisit(this); } else if (id == MENU_CACHE_DETAILS) { - Intent cachesIntent = new Intent(this, cgeodetail.class); + final Intent cachesIntent = new Intent(this, cgeodetail.class); + final cgCache cache = getCacheFromAdapter(adapterInfo); cachesIntent.putExtra("geocode", cache.getGeocode().toUpperCase()); cachesIntent.putExtra("name", cache.getName()); startActivity(cachesIntent); @@ -1273,7 +1265,7 @@ public class cgeocaches extends AbstractListActivity { } else if (id == MENU_FILTER_TYPE_GPS) { return setFilter(new cgFilterByType(CacheType.GPS_EXHIBIT)); } else if (id == MENU_DROP_CACHE) { - cgBase.dropCache(app, cache, new Handler() { + cgBase.dropCache(app, getCacheFromAdapter(adapterInfo), new Handler() { @Override public void handleMessage(Message msg) { refreshCurrentList(); @@ -1281,19 +1273,18 @@ public class cgeocaches extends AbstractListActivity { }); return true; } else if (id >= CONTEXT_MENU_MOVE_TO_LIST && id < CONTEXT_MENU_MOVE_TO_LIST + 100) { - int newListId = id - CONTEXT_MENU_MOVE_TO_LIST; - if (cache != null) { - app.moveToList(cache.getGeocode(), newListId); + final int newListId = id - CONTEXT_MENU_MOVE_TO_LIST; + if (adapterInfo != null) { + app.moveToList(getCacheFromAdapter(adapterInfo).getGeocode(), newListId); } adapter.resetChecks(); refreshCurrentList(); return true; } else if (id >= MENU_MOVE_SELECTED_OR_ALL_TO_LIST && id < MENU_MOVE_SELECTED_OR_ALL_TO_LIST + 100) { - int newListId = id - MENU_MOVE_SELECTED_OR_ALL_TO_LIST; - boolean moveAll = adapter.getChecked() == 0; - final List<cgCache> cacheListTemp = new ArrayList<cgCache>(cacheList); - for (cgCache c : cacheListTemp) { + final int newListId = id - MENU_MOVE_SELECTED_OR_ALL_TO_LIST; + final boolean moveAll = adapter.getChecked() == 0; + for (final cgCache c : Collections.unmodifiableList(cacheList)) { if (moveAll || c.isStatusChecked()) { app.moveToList(c.getGeocode(), newListId); } @@ -1309,8 +1300,9 @@ public class cgeocaches extends AbstractListActivity { // https://code.google.com/p/android/issues/detail?id=7139 lastMenuInfo = info; - if (cache != null) { + if (adapterInfo != null) { // create a search for a single cache (as if in details view) + final cgCache cache = getCacheFromAdapter(adapterInfo); final cgSearch singleSearch = base.searchByGeocode(cache.getGeocode(), null, 0, false, null); if (NavigationAppFactory.onMenuItemSelected(item, geo, this, @@ -1324,6 +1316,17 @@ public class cgeocaches extends AbstractListActivity { return true; } + /** + * Extract a cache from adapter data. + * + * @param adapterInfo + * an adapterInfo + * @return the pointed cache + */ + private cgCache getCacheFromAdapter(final AdapterContextMenuInfo adapterInfo) { + return adapter.getItem(adapterInfo.position); + } + private boolean setFilter(cgFilter filter) { if (adapter != null) { adapter.setFilter(filter); diff --git a/main/src/cgeo/geocaching/gcvote/GCVote.java b/main/src/cgeo/geocaching/gcvote/GCVote.java index 7dec3f9..a835b83 100644 --- a/main/src/cgeo/geocaching/gcvote/GCVote.java +++ b/main/src/cgeo/geocaching/gcvote/GCVote.java @@ -5,7 +5,6 @@ import cgeo.geocaching.Settings; import cgeo.geocaching.cgBase; import cgeo.geocaching.cgCache; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -66,7 +65,7 @@ public final class GCVote { params.put("userName", login.left, "password", login.right); } } - if (CollectionUtils.isNotEmpty(guids)) { + if (guids != null && !guids.isEmpty()) { params.put("cacheIds", StringUtils.join(guids.toArray(), ',')); } else { params.put("waypoints", StringUtils.join(geocodes.toArray(), ',')); |