Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Pointer Exception in Android SDK when accessing "publish_details" array #30

Closed
philculver opened this issue Apr 21, 2023 · 1 comment

Comments

@philculver
Copy link

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:

  1. Integrate ContentStack Android SDK into an Android project.
  2. Fetch a JSON object that does not contain the "publish_details" array or contains a null value for it.
  3. 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.

Screen Shot 2023-03-16 at 4 30 56 PM

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");
}
@ishaileshmishra
Copy link
Member

Thank you for writing to us, @philculver. We are working on it and will update you soon with the updated dependency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants