Skip to content

org.json.JSONObject.NULL not handled properly wherever user authData is concerned #405

Closed
@yuzeh

Description

@yuzeh

I'm getting this stack trace after logging in (to a self-hosted parse-server) from an anonymous user that's been saved to the cloud:

02-23 17:02:46.743 E/OMG     ( 3180): com.parse.ParseException: java.lang.ClassCastException: org.json.JSONObject$1 cannot be cast to java.util.Map
02-23 17:02:46.743 E/OMG     ( 3180):   at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:114)
02-23 17:02:46.743 E/OMG     ( 3180):   at android.os.Handler.handleCallback(Handler.java:739)
02-23 17:02:46.743 E/OMG     ( 3180):   at android.os.Handler.dispatchMessage(Handler.java:95)
02-23 17:02:46.743 E/OMG     ( 3180):   at android.os.Looper.loop(Looper.java:148)
02-23 17:02:46.743 E/OMG     ( 3180):   at android.app.ActivityThread.main(ActivityThread.java:5417)
02-23 17:02:46.743 E/OMG     ( 3180):   at java.lang.reflect.Method.invoke(Native Method)
02-23 17:02:46.743 E/OMG     ( 3180):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
02-23 17:02:46.743 E/OMG     ( 3180):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
02-23 17:02:46.743 E/OMG     ( 3180): Caused by: java.lang.ClassCastException: org.json.JSONObject$1 cannot be cast to java.util.Map
02-23 17:02:46.743 E/OMG     ( 3180):   at com.parse.ParseUser.getAuthData(ParseUser.java:340)
02-23 17:02:46.743 E/OMG     ( 3180):   at com.parse.ParseUser.synchronizeAuthDataAsync(ParseUser.java:1245)
02-23 17:02:46.743 E/OMG     ( 3180):   at com.parse.ParseUser.synchronizeAllAuthDataAsync(ParseUser.java:1234)
02-23 17:02:46.743 E/OMG     ( 3180):   at com.parse.CachedCurrentUserController$1$2.then(CachedCurrentUserController.java:71)
02-23 17:02:46.743 E/OMG     ( 3180):   at com.parse.CachedCurrentUserController$1$2.then(CachedCurrentUserController.java:67)

Looks like ParseUser#getAuthData(String) is not handling org.json.JSONObject.NULL (I assume that's what org.json.JSONObject$1 is) properly.

I think the core of the problem is that ParseUser#getAuthData() has return type Map<String, Map<String, String>>. As it turns out, sometimes, you can encounter a JSONObject.NULL as a value in this map. The lack of JSONObject.NULL awareness causes a few other issues too:

This problem goes away when pointing to hosted Parse because the hosted Parse implementation will never send down "authData": {"anonymous": null} as part of the User object -- somehow, the "authData" property is cleaned of null values before being sent down. (Should I file a separate issue against parse-server?)

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