Description
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:
- The comments here indicate we should be checking for
JSONObject.NULL
but the code actually checks fornull
: https://github.com/ParsePlatform/Parse-SDK-Android/blob/f439b3d3ba02eaad52e653b6890b3a10e74168da/Parse/src/main/java/com/parse/ParseUser.java#L607 - Should also check for
JSONObject.NULL
here: https://github.com/ParsePlatform/Parse-SDK-Android/blob/f439b3d3ba02eaad52e653b6890b3a10e74168da/Parse/src/main/java/com/parse/ParseUser.java#L1217
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?)