Login with invalid identity using android SDK

Hi all,

When I login with invalid Identity, I am suppose to get fault code 3003 or whatever listed in below link, but I get fault code, BackendlessFault{ code: ‘0’, message: ‘java.lang.NullPointerException’ }

https://backendless.com/documentation/users/android/users_overview.htm

Regards,
Scott

Hello, Scott!

Unfortunately I cannot reproduce this issue. Can you please provide more information about this case? For example, what is the users identity in your app? Do you use any null values in the method? Are you calling this method from device or from pure java?

I’ve checked it with android SDK version 2.0.4. Are you using the same?

best regards,
Alex

Hi Alex,

I pulled latest Android SDK from Github, but still getting the same result.
There’s no problem to login with user with valid id and password.

Do you use any null values in the method?
=> I don’t use null values in the method

Are you calling this method from device or from pure java?
=> I am calling from device (Android ICS)

what is the users identity in your app?
=> below is my code
String dummyId = “test”;
String dummyPass = “pass”;
Backendless.UserService.login(dummyId, dummyPass, new AsyncCallback<BackendlessUser>() {

Regards,
Scott

Have you marked this “dummyId” field as an identity in Backendless console?
Also, do you have any event handlers associated with login?

Hi Sergey,

I found way to reproduce.
I have following afterLogin servercode, if I disable servercode, there’s no problem.
If you add below servercode, you can reproduce the problem.
How do I check if user is logged in or not within “afterlogin”?
Should I check for result!=null && result.getResult!=null?

public void afterLogin( RunnerContext context, String login, String password, ExecutionResult&lt;HashMap&gt; result ) throws Exception

{		

	HashMap map = result.getResult();

	map.put("loginTime", new Date());

}

FYI, even if I leave afterlogin empty like below, I get the same result. code: ‘0’, message: ‘java.lang.NullPointerException’

If user is disabled user, I get the same result as well - seems like having afterlogin servercode, proper error code isn’t returned.

Hi Scott,

Try calling result.getException(), see if it returns a non-null value.

Regards,
Mark

I am confused, right here you wrote:

“I have following afterLogin servercode, if I disable servercode, there’s no problem.”

But now it is not working. What has changed?

Mark

Hi Mark,

Same thing, whether I have result.getException(), or leave afterlogin blank, I get NullPointerException w/ error code 0 from client.

Okay, let me explain.
Disable servercode mean remove servercode from console. (console, enable/disable checkmark, I unchecked and it works)

Empty function, like below returns same error.

@Override

public void afterLogin( RunnerContext context, String login, String password, ExecutionResult&lt;HashMap&gt; result ) throws Exception

{						

}

How do you explain your message saying that if you leave server code out, it works as expected?

Because I get valid error code.

For example, when I leave server code out, and

  1. trying to login with disabled user, I get valid fault code which is 3088 and message “disabled user”
  2. trying to login with invalid user Id, I get 3003, invalid login or password.

Thanks for clarifying. Simply the presence of a no-op afterLogin function changes the response. I will open an internal ticket to investigate the problem.

Regards,
Mark

Thanks Mark,

Please let me know when it gets resolved.

Hi, Scott,
Didn’t you forget to rebuild / redeploy your code after leaving the handler empty?

Hi Sergey,

I don’t know why but, now leaving handler empty does respond with proper fault code.
I always clean and build though - Yesterday I clean/build/redeployed 3 times with empty handler.
Regarding servercode, sometimes previously deployed servercode is executed, I’ve experienced at least 2 times, I don’t know if this is code runner deploy issue.

HashMap map = result.getResult();
map.put("loginTime", new Date());

This is where you were getting NullPointerException: you receive an error, thus result.getResult() returns null, and then you try to put a value to a null map.
Just add a check whether result.getResult() is not null.

Thanks for update.