aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorbananeweizen <bananeweizen@gmx.de>2011-10-31 19:21:25 +0100
committerbananeweizen <bananeweizen@gmx.de>2011-10-31 19:21:25 +0100
commit5bf29d09cf3d19e863e7bdca3dbe3d108c137799 (patch)
treea84ab256f5fb5dd10f039a9dbc36ad9acb04a8da /main
parent28f8b812092ebe6015a53f0f60bc838ffe24f270 (diff)
downloadcgeo-5bf29d09cf3d19e863e7bdca3dbe3d108c137799.zip
cgeo-5bf29d09cf3d19e863e7bdca3dbe3d108c137799.tar.gz
cgeo-5bf29d09cf3d19e863e7bdca3dbe3d108c137799.tar.bz2
avoid NPE when accessing cache type, #737
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/cgCache.java11
-rw-r--r--main/src/cgeo/geocaching/enumerations/CacheType.java12
2 files changed, 18 insertions, 5 deletions
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index 5406e90..edca68a 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -50,7 +50,7 @@ public class cgCache implements ICache {
private String geocode = "";
private String cacheId = "";
private String guid = "";
- private CacheType cacheType = null;
+ private CacheType cacheType = CacheType.UNKNOWN;
private String name = "";
private Spannable nameSp = null;
private String owner = "";
@@ -128,7 +128,7 @@ public class cgCache implements ICache {
if (StringUtils.isBlank(guid)) {
guid = other.getGuid();
}
- if (null == cacheType) {
+ if (null == cacheType || CacheType.UNKNOWN == cacheType) {
cacheType = other.getCacheType();
}
if (StringUtils.isBlank(name)) {
@@ -918,7 +918,12 @@ public class cgCache implements ICache {
}
public void setCacheType(CacheType cacheType) {
- this.cacheType = cacheType;
+ if (cacheType == null) {
+ this.cacheType = CacheType.UNKNOWN;
+ }
+ else {
+ this.cacheType = cacheType;
+ }
}
}
diff --git a/main/src/cgeo/geocaching/enumerations/CacheType.java b/main/src/cgeo/geocaching/enumerations/CacheType.java
index 1e58b70..e8f19cc 100644
--- a/main/src/cgeo/geocaching/enumerations/CacheType.java
+++ b/main/src/cgeo/geocaching/enumerations/CacheType.java
@@ -55,11 +55,19 @@ public enum CacheType {
}
public final static CacheType getById(final String id) {
- return CacheType.FIND_BY_ID.get(id.toLowerCase().trim());
+ final CacheType result = CacheType.FIND_BY_ID.get(id.toLowerCase().trim());
+ if (result == null) {
+ return UNKNOWN;
+ }
+ return result;
}
public final static CacheType getByPattern(final String pattern) {
- return CacheType.FIND_BY_PATTERN.get(pattern.toLowerCase().trim());
+ final CacheType result = CacheType.FIND_BY_PATTERN.get(pattern.toLowerCase().trim());
+ if (result == null) {
+ return UNKNOWN;
+ }
+ return result;
}
}