Skip to content

Commit

Permalink
check null source in JSONUtils.queryJSON()
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Sep 28, 2015
1 parent 58440ae commit 68f5328
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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=".";
Expand All @@ -25,6 +24,10 @@ public class JSONUtils {
* traverse the object graph and pull out the desired property
*/
public static <U> 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) {
Expand Down Expand Up @@ -89,7 +92,11 @@ public static <U> 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> U queryJSON(JSONArray source, String query, U defaultObject){
public static <U> 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);
Expand Down

0 comments on commit 68f5328

Please sign in to comment.