diff --git a/mobile/android/base/background/healthreport/HealthReportGenerator.java b/mobile/android/base/background/healthreport/HealthReportGenerator.java index 0b791768834d..d57e150522f7 100644 --- a/mobile/android/base/background/healthreport/HealthReportGenerator.java +++ b/mobile/android/base/background/healthreport/HealthReportGenerator.java @@ -427,7 +427,16 @@ public class HealthReportGenerator { /** * Compute the *tree* difference set between the two objects. If the two - * objects are identical, returns null. + * objects are identical, returns null. If from is + * null, returns to. If to is + * null, behaves as if to 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. @@ -445,10 +454,14 @@ public class HealthReportGenerator { 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 toKeys = includeNull ? new HashSet(to.length())