Bug 888665 - Bad stored add-ons cause document generation failure in the presence of good add-ons. r=nalexander
--- a/mobile/android/base/background/healthreport/HealthReportGenerator.java
+++ b/mobile/android/base/background/healthreport/HealthReportGenerator.java
@@ -422,17 +422,26 @@ public class HealthReportGenerator {
return null;
}
counts.put("_v", 1);
return counts;
}
/**
* Compute the *tree* difference set between the two objects. If the two
- * objects are identical, returns null.
+ * objects are identical, returns <code>null</code>. If <code>from</code> is
+ * <code>null</code>, returns <code>to</code>. If <code>to</code> is
+ * <code>null</code>, behaves as if <code>to</code> were an empty object.
+ *
+ * (Note that this method does not check for {@link JSONObject#NULL}, because
+ * by definition it can't be provided as input to this method.)
+ *
+ * This behavior is intended to simplify life for callers: a missing object
+ * can be viewed as (and behaves as) an empty map, to a useful extent, rather
+ * than throwing an exception.
*
* @param from
* a JSONObject.
* @param to
* a JSONObject.
* @param includeNull
* if true, keys present in <code>from</code> but not in
* <code>to</code> are included as {@link JSONObject#NULL} in the
@@ -440,20 +449,24 @@ public class HealthReportGenerator {
*
* @return a JSONObject, or null if the two objects are identical.
* @throws JSONException
* should not occur, but...
*/
public static JSONObject diff(JSONObject from,
JSONObject to,
boolean includeNull) throws JSONException {
- if (from == null || from == JSONObject.NULL) {
+ if (from == null) {
return to;
}
+ if (to == null) {
+ return diff(from, new JSONObject(), includeNull);
+ }
+
JSONObject out = new JSONObject();
HashSet<String> toKeys = includeNull ? new HashSet<String>(to.length())
: null;
@SuppressWarnings("unchecked")
Iterator<String> it = to.keys();
while (it.hasNext()) {