Skip to content

Commit 79839e0

Browse files
committed
check null source in JSONUtils.queryJSON()
1 parent 41a6352 commit 79839e0

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/JSONUtils.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.wordpress.android.util.AppLog.T;
99

1010
import java.util.ArrayList;
11-
import java.util.Iterator;
1211

1312
public class JSONUtils {
1413
private static String QUERY_SEPERATOR=".";
@@ -25,6 +24,10 @@ public class JSONUtils {
2524
* traverse the object graph and pull out the desired property
2625
*/
2726
public static <U> U queryJSON(JSONObject source, String query, U defaultObject) {
27+
if (source == null) {
28+
AppLog.e(T.UTILS, "Parameter source is null, can't query a null object");
29+
return defaultObject;
30+
}
2831
int nextSeperator = query.indexOf(QUERY_SEPERATOR);
2932
int nextIndexStart = query.indexOf(QUERY_ARRAY_INDEX_START);
3033
if (nextSeperator == -1 && nextIndexStart == -1) {
@@ -89,7 +92,11 @@ public static <U> U queryJSON(JSONObject source, String query, U defaultObject)
8992
* Acceptable indexes include negative numbers to reference items from the end of
9093
* the list as well as "last" and "first" as more explicit references to "0" and "-1"
9194
*/
92-
public static <U> U queryJSON(JSONArray source, String query, U defaultObject){
95+
public static <U> U queryJSON(JSONArray source, String query, U defaultObject) {
96+
if (source == null) {
97+
AppLog.e(T.UTILS, "Parameter source is null, can't query a null object");
98+
return defaultObject;
99+
}
93100
// query must start with [ have an index and then have ]
94101
int indexStart = query.indexOf(QUERY_ARRAY_INDEX_START);
95102
int indexEnd = query.indexOf(QUERY_ARRAY_INDEX_END);

0 commit comments

Comments
 (0)