Skip to content

Commit a9b52ce

Browse files
committed
Check null query string
1 parent 1735ccb commit a9b52ce

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
import java.util.ArrayList;
1111

1212
public class JSONUtils {
13-
private static String QUERY_SEPERATOR=".";
14-
private static String QUERY_ARRAY_INDEX_START="[";
15-
private static String QUERY_ARRAY_INDEX_END="]";
16-
private static String QUERY_ARRAY_FIRST="first";
17-
private static String QUERY_ARRAY_LAST="last";
13+
private static String QUERY_SEPERATOR = ".";
14+
private static String QUERY_ARRAY_INDEX_START = "[";
15+
private static String QUERY_ARRAY_INDEX_END = "]";
16+
private static String QUERY_ARRAY_FIRST = "first";
17+
private static String QUERY_ARRAY_LAST = "last";
1818

1919
private static final String JSON_NULL_STR = "null";
20+
private static final String TAG = "JSONUtils";
2021

21-
private static final String TAG="JSONUtils";
2222
/**
2323
* Given a JSONObject and a key path (e.g property.child) and a default it will
2424
* traverse the object graph and pull out the desired property
@@ -28,6 +28,10 @@ public static <U> U queryJSON(JSONObject source, String query, U defaultObject)
2828
AppLog.e(T.UTILS, "Parameter source is null, can't query a null object");
2929
return defaultObject;
3030
}
31+
if (query == null) {
32+
AppLog.e(T.UTILS, "Parameter query is null");
33+
return defaultObject;
34+
}
3135
int nextSeperator = query.indexOf(QUERY_SEPERATOR);
3236
int nextIndexStart = query.indexOf(QUERY_ARRAY_INDEX_START);
3337
if (nextSeperator == -1 && nextIndexStart == -1) {
@@ -59,9 +63,6 @@ public static <U> U queryJSON(JSONObject source, String query, U defaultObject)
5963
String nextQuery = query.substring(endQuery);
6064
String key = query.substring(0, endQuery);
6165
try {
62-
if (source == null) {
63-
return defaultObject;
64-
}
6566
if (nextQuery.indexOf(QUERY_SEPERATOR) == 0) {
6667
return queryJSON(source.getJSONObject(key), nextQuery.substring(1), defaultObject);
6768
} else if (nextQuery.indexOf(QUERY_ARRAY_INDEX_START) == 0) {
@@ -97,6 +98,10 @@ public static <U> U queryJSON(JSONArray source, String query, U defaultObject) {
9798
AppLog.e(T.UTILS, "Parameter source is null, can't query a null object");
9899
return defaultObject;
99100
}
101+
if (query == null) {
102+
AppLog.e(T.UTILS, "Parameter query is null");
103+
return defaultObject;
104+
}
100105
// query must start with [ have an index and then have ]
101106
int indexStart = query.indexOf(QUERY_ARRAY_INDEX_START);
102107
int indexEnd = query.indexOf(QUERY_ARRAY_INDEX_END);

0 commit comments

Comments
 (0)