-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Description:
While using the ContentStack Android SDK version 3.10.0, we encountered a null pointer exception when attempting to access the "publish_details" array from a JSON object. This issue occurs when the JSON object does not contain the "publish_details" array or when the array is null. It leads to a warning in the app when trying to call the length() method on a null object.
Steps to reproduce:
- Integrate ContentStack Android SDK into an Android project.
- Fetch a JSON object that does not contain the "publish_details" array or contains a null value for it.
- Attempt to access and iterate through the "publish_details" array using the provided SDK code.
Expected behavior:
The SDK should handle cases where the "publish_details" array is not present or is null without throwing a null pointer exception.
Actual behavior:
A null pointer exception is thrown when trying to call the length() method on a null object, leading to warnings in the app.
Proposed solution:
Add a null check before iterating through the publishArray. Here's a suggested modification to the SDK code:
if (publishArray != null) {
for (int i = 0; i < publishArray.length(); i++) {
JSONObject publishObject = publishArray.optJSONObject(i);
Iterator<String> iterator = publishObject.keys();
HashMap<String, Object> hashMap = new HashMap<>();
while (iterator.hasNext()) {
String key = iterator.next();
hashMap.put(key, publishObject.opt(key));
}
}
} else {
Log.e("ContentStack", "publish_details array not found or is null");
}