From 1735ccbf43b5cbb48933635340fd63fd0ab01a58 Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Mon, 28 Sep 2015 15:08:05 +0200 Subject: [PATCH] check null source in JSONUtils.queryJSON() --- .../java/org/wordpress/android/util/JSONUtils.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/JSONUtils.java b/WordPressUtils/src/main/java/org/wordpress/android/util/JSONUtils.java index 4c92478cb4d7..6df9e0b0aa9d 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/JSONUtils.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/JSONUtils.java @@ -8,7 +8,6 @@ import org.wordpress.android.util.AppLog.T; import java.util.ArrayList; -import java.util.Iterator; public class JSONUtils { private static String QUERY_SEPERATOR="."; @@ -25,6 +24,10 @@ public class JSONUtils { * traverse the object graph and pull out the desired property */ public static U queryJSON(JSONObject source, String query, U defaultObject) { + if (source == null) { + AppLog.e(T.UTILS, "Parameter source is null, can't query a null object"); + return defaultObject; + } int nextSeperator = query.indexOf(QUERY_SEPERATOR); int nextIndexStart = query.indexOf(QUERY_ARRAY_INDEX_START); if (nextSeperator == -1 && nextIndexStart == -1) { @@ -89,7 +92,11 @@ public static U queryJSON(JSONObject source, String query, U defaultObject) * Acceptable indexes include negative numbers to reference items from the end of * the list as well as "last" and "first" as more explicit references to "0" and "-1" */ - public static U queryJSON(JSONArray source, String query, U defaultObject){ + public static U queryJSON(JSONArray source, String query, U defaultObject) { + if (source == null) { + AppLog.e(T.UTILS, "Parameter source is null, can't query a null object"); + return defaultObject; + } // query must start with [ have an index and then have ] int indexStart = query.indexOf(QUERY_ARRAY_INDEX_START); int indexEnd = query.indexOf(QUERY_ARRAY_INDEX_END);