Parse-SDK-Android icon indicating copy to clipboard operation
Parse-SDK-Android copied to clipboard

ParseUser.getCurrentUser() sometimes returning null

Open slpereira opened this issue 8 years ago • 8 comments

I am experiencing some strange behaviour in my android app. Some weeks ago I activated the Google Analytics Crash Report on my app, and sometimes I can see a NullPointerException been raised just in the statement ParseUser.getCurrentUser().getString(...). The activity where this happens is only accessed after the user has been logged in. I don't know why this happens. I know about a closed issue #179 reporting the same problem, but I decided to open a new one. I tried reproduce the problem in many different situations, but I can't reproduced the error.

slpereira avatar May 23 '16 00:05 slpereira

That is a bug in Parse core. Very difficult to reproduce it.

nthuat avatar May 23 '16 04:05 nthuat

We have the same problem. The workaround we are using now is saving the username and password in SharedPreference, and when ParseUser.getCurrentUser() returns null, we log the user in manually:

final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
ParseUser.logIn(sp.getString("username", null), sp.getString("password", null));

iForests avatar May 25 '16 03:05 iForests

@iForests I highly recommend against doing this as it compromises the user's credentials by storing it in plaintext.

grantland avatar May 25 '16 03:05 grantland

@grantland Oh, there're only anonymous users in our app, so I think it's okay in this situation.

iForests avatar May 25 '16 03:05 iForests

@iForests I still don't recommend it as it compromises the user's account.

grantland avatar May 25 '16 04:05 grantland

I can reproduce this issue. We have extended ParseUser class to add our custom data and many times when we try to resume the home activity, we can see this crash coming in. ClassCastException.

keyur47831 avatar Jun 23 '16 07:06 keyur47831

@keyur47831 Did you find a fix ?

McGalanes avatar Jun 20 '18 13:06 McGalanes

I did experienced the same issue. It turns out that my problem was that I was pinning objects without waiting for the callback. ie : I was pinning several ParseObjects consecutively without waiting for the pin operation to complete. Seems to be a problem for Parse... Since after that the LocalDataStore was corrupted and the CurrentParseUser was null.

Hope that'll help

nicolas71640 avatar Oct 24 '19 15:10 nicolas71640