aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/Geocache.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/Geocache.java')
-rw-r--r--main/src/cgeo/geocaching/Geocache.java28
1 files changed, 27 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index 18a315c..e672ca8 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -618,15 +618,27 @@ public class Geocache implements ICache, IWaypoint {
@Override
public String getHint() {
initializeCacheTexts();
+ assertTextNotNull(hint, "Hint");
return hint;
}
/**
+ * After lazy loading the lazily loaded field must be non {@code null}.
+ *
+ */
+ private static void assertTextNotNull(final String field, final String name) throws InternalError {
+ if (field == null) {
+ throw new InternalError(name + " field is not allowed to be null here");
+ }
+ }
+
+ /**
* Attention, calling this method may trigger a database access for the cache!
*/
@Override
public String getDescription() {
initializeCacheTexts();
+ assertTextNotNull(description, "Description");
return description;
}
@@ -635,7 +647,19 @@ public class Geocache implements ICache, IWaypoint {
*/
private void initializeCacheTexts() {
if (description == null || shortdesc == null || hint == null || location == null) {
- cgData.loadCacheTexts(this);
+ Geocache partial = cgData.loadCacheTexts(this.getGeocode());
+ if (description == null) {
+ setDescription(partial.getDescription());
+ }
+ if (shortdesc == null) {
+ setShortDescription(partial.getShortDescription());
+ }
+ if (hint == null) {
+ setHint(partial.getHint());
+ }
+ if (location == null) {
+ setLocation(partial.getLocation());
+ }
}
}
@@ -645,6 +669,7 @@ public class Geocache implements ICache, IWaypoint {
@Override
public String getShortDescription() {
initializeCacheTexts();
+ assertTextNotNull(shortdesc, "Short description");
return shortdesc;
}
@@ -673,6 +698,7 @@ public class Geocache implements ICache, IWaypoint {
@Override
public String getLocation() {
initializeCacheTexts();
+ assertTextNotNull(location, "Location");
return location;
}