Bug 1321562 - Fix bugs in GeckoBundle.fromJSONObject; r=me
authorJim Chen <nchen@mozilla.com>
Thu, 01 Dec 2016 12:25:22 -0500
changeset 325033 083ffc01652a13e80d12288074fd5dbc39621e93
parent 325032 47e2650093d575c5042b43feb0575ef9678352b1
child 325034 b49684127ce464141b0a989cd621cb4794b6a85f
child 325065 8083de7bddbc48c2cdf35c4810746b4e6ea9d13f
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersme
bugs1321562
milestone53.0a1
Bug 1321562 - Fix bugs in GeckoBundle.fromJSONObject; r=me Fix a crash in GeckoBundle.fromJSONObject due to wrong values array type. Also, fix a bug where the first element of a converted array is repeated. r=me for trivial patch.
mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GeckoBundle.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GeckoBundle.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/GeckoBundle.java
@@ -631,17 +631,17 @@ public final class GeckoBundle {
         if (value instanceof JSONArray) {
             final JSONArray array = (JSONArray) value;
             final int len = array.length();
             if (len == 0) {
                 return EMPTY_BOOLEAN_ARRAY;
             }
             Object out = null;
             for (int i = 0; i < len; i++) {
-                final Object element = fromJSONValue(array.opt(0));
+                final Object element = fromJSONValue(array.opt(i));
                 if (element == null) {
                     continue;
                 }
                 if (out == null) {
                     Class<?> type = element.getClass();
                     if (type == Boolean.class) {
                         type = boolean.class;
                     } else if (type == Integer.class) {
@@ -672,17 +672,17 @@ public final class GeckoBundle {
     }
 
     public static GeckoBundle fromJSONObject(final JSONObject obj) throws JSONException {
         if (obj == null || obj == JSONObject.NULL) {
             return null;
         }
 
         final String[] keys = new String[obj.length()];
-        final Object[] values = new String[obj.length()];
+        final Object[] values = new Object[obj.length()];
 
         final Iterator<String> iter = obj.keys();
         for (int i = 0; iter.hasNext(); i++) {
             final String key = iter.next();
             keys[i] = key;
             values[i] = fromJSONValue(obj.opt(key));
         }
         return new GeckoBundle(keys, values);