Skip to content
Browse files

Fix for HER-1962 NPE from missing sheet

* SheetOverlaysManager.java
    getOverlayMap(String) - return null if sheet missing instead of triggering npe
* KeyedProperties.java
    get(String) - check for null return value from getOverlayMap() and log warning
  • Loading branch information...
1 parent 9b418bb commit 995133dc407c4e167bea37b0a8030e25fe6a97ce @nlevitt nlevitt committed
View
16 commons/src/main/java/org/archive/spring/KeyedProperties.java
@@ -24,6 +24,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Logger;
/**
* Map for storing overridable properties.
@@ -36,6 +37,9 @@
*/
public class KeyedProperties extends ConcurrentHashMap<String,Object> {
private static final long serialVersionUID = 3403222335436162778L;
+
+ private static final Logger logger = Logger.getLogger(KeyedProperties.class.getName());
+
/** the alternate global property-paths leading to this map
* TODO: consider if deterministic ordered list is important */
HashSet<String> externalPaths = new HashSet<String>();
@@ -61,11 +65,15 @@ public Object get(String key) {
for(int j = ocontext.getOverlayNames().size()-1; j>=0; j--) {
String name = ocontext.getOverlayNames().get(j);
Map<String,Object> m = ocontext.getOverlayMap(name);
- for(String ok : getOverrideKeys(key)) {
- Object val = m.get(ok);
- if(val!=null) {
- return val;
+ if (m != null) {
+ for(String ok : getOverrideKeys(key)) {
+ Object val = m.get(ok);
+ if(val!=null) {
+ return val;
+ }
}
+ } else {
+ logger.warning("sheet '" + name + "' should apply but there is no such sheet!");
}
}
}
View
7 engine/src/main/java/org/archive/crawler/spring/SheetOverlaysManager.java
@@ -169,7 +169,12 @@ public void addSurtsAssociation(SurtPrefixesSheetAssociation assoc) {
* @see org.archive.spring.OverlayMapsSource#getOverlayMap(java.lang.String)
*/
public Map<String, Object> getOverlayMap(String name) {
- return sheetsByName.get(name).getMap();
+ Sheet sheet = sheetsByName.get(name);
+ if (sheet != null) {
+ return sheet.getMap();
+ } else {
+ return null;
+ }
}
/**

0 comments on commit 995133d

Please sign in to comment.
Something went wrong with that request. Please try again.