Bug 888665 - Bad stored add-ons cause document generation failure in the presence of good add-ons. r=nalexander
authorRichard Newman <rnewman@mozilla.com>
Tue, 02 Jul 2013 12:08:09 -0700
changeset 144772 a0a3099e79d51885eca5b02f3133e55a182903fe
parent 144771 2ae11ca43e447fe73ca3d098d896ceab33c5aab3
child 144773 df51b4ba96c3394c2cab3cdcf7fff91eb1044c1f
push idunknown
push userunknown
push dateunknown
reviewersnalexander
bugs888665
milestone25.0a1
Bug 888665 - Bad stored add-ons cause document generation failure in the presence of good add-ons. r=nalexander
mobile/android/base/background/healthreport/HealthReportGenerator.java
--- 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()) {