Skip to content

Potential NPE when handling data #336

Closed
@INRIX-Owais-Ali

Description

@INRIX-Owais-Ali

We're seeing the following crash being reported in our app (using Parse 1.11.0):

Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.inrix.android.app.push.PdaBroadcastReceiver: java.lang.NullPointerException
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:2325)
       at android.app.ActivityThread.access$1500(ActivityThread.java:130)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1287)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:4847)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:535)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.NullPointerException
       at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
       at org.json.JSONTokener.nextValue(JSONTokener.java:94)
       at org.json.JSONObject.(JSONObject.java)
       at org.json.JSONObject.(JSONObject.java)
       at com.parse.ParsePushBroadcastReceiver.onPushReceive(SourceFile:141)
       at com.parse.ParsePushBroadcastReceiver.onReceive(SourceFile:117)
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:2312)
       at android.app.ActivityThread.access$1500(ActivityThread.java:130)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1287)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:4847)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:535)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
       at dalvik.system.NativeStart.main(NativeStart.java)

The relevant code block is:

    JSONObject pushData = null;
    try {
      pushData = new JSONObject(intent.getStringExtra(KEY_PUSH_DATA));
    } catch (JSONException e) {
      PLog.e(TAG, "Unexpected JSONException when receiving push data: ", e);
    }

It seems like JSONObject constructor can throw NPE if the value being passed in is null (or there may be some other root cause).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions