ably / ably-java

Java, Android, Clojure and Scala client library SDK for Ably realtime messaging service
https://ably.com/download
Apache License 2.0
85 stars 40 forks source link

NullPointerException: Attempt to invoke interface method 'java.lang.String java.security.Principal.getName()' on a null object reference #41

Closed stannedelchev closed 8 years ago

stannedelchev commented 9 years ago
  1. Create a new Android project in Android Studio via the Simple Activity template
  2. Attach ably-android.jar in project
  3. Replace code in MainActivity with code from here and fix package name.
  4. Run on device
  5. Get exception when calling channel.history() on line 61:

io.ably.types.AblyException: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.security.Principal.getName()' on a null object reference

Here's the full log:

W/ActivityThread﹕ Application com.example.stan.myapplication is waiting for the debugger on port 8100...
I/art﹕ Late-enabling -Xcheck:jni
I/art﹕ VMHOOK: rlim_cur : 0 pid:12814
I/System.out﹕ Sending WAIT chunk
I/System.out﹕ (INFO): io.ably.realtime.AblyRealtime: started
I/System.out﹕ (INFO): Auth(): using token auth with client-side signing
I/System.out﹕ (VERBOSE): io.ably.transport.ConnectionManager: requestState(): requesting connecting; id = null
I/System.out﹕ (VERBOSE): io.ably.transport.ConnectionManager: notifyState(): notifying connecting; id = null
I/System.out﹕ (INFO): TokenAuth.authorise():
I/System.out﹕ (INFO): TokenAuth.authorise(): requesting new token
I/System.out﹕ (INFO): Auth.requestToken(): using token auth with client-side signing
I/System.out﹕ (INFO): Auth.getTokenRequest(): generated signed request
D/libc﹕ [NET] android_getaddrinfofornet+,hn 12(0x726573742e6162),sn(),hints(known),family 0,flags 4
D/libc﹕ [NET] android_getaddrinfofornet-, err=8
D/libc﹕ [NET] android_getaddrinfofornet+,hn 12(0x726573742e6162),sn(),hints(known),family 0,flags 1024
D/libc﹕ [NET] android_getaddrinfofornet-, pass to proxy
D/libc﹕ [NET] android_getaddrinfo_proxy+
D/libc﹕ [NET] android_getaddrinfo_proxy get netid:0
D/Atlas﹕ Validating map...
D/libc﹕ [NET] android_getaddrinfo_proxy-, success
D/libc﹕ [NET] android_getaddrinfofornet+,hn 13(0x35342e39332e31),sn(),hints(known),family 0,flags 4
D/libc﹕ [NET] android_getaddrinfofornet-, SUCCESS
I/System.out﹕ (INFO): TokenAuth.setTokenDetails():
I/System.out﹕ (INFO): TokenAuth.getTokenDetails():
I/System.out﹕ (VERBOSE): io.ably.transport.ConnectionManager: setState(): setting connecting
V/ABLY CONNECTION CHANGE﹕ connecting
D/libc﹕ [NET] android_getaddrinfofornet+,hn 16(0x7265616c74696d),sn(),hints(known),family 0,flags 4
D/libc﹕ [NET] android_getaddrinfofornet-, err=8
D/libc﹕ [NET] android_getaddrinfofornet+,hn 16(0x7265616c74696d),sn(),hints(known),family 0,flags 1024
D/libc﹕ [NET] android_getaddrinfofornet-, pass to proxy
D/libc﹕ [NET] android_getaddrinfo_proxy+
D/libc﹕ [NET] android_getaddrinfo_proxy get netid:0
D/libc﹕ [NET] android_getaddrinfo_proxy-, success
I/System.out﹕ (VERBOSE): io.ably.transport.ConnectionManager: notifyState(): notifying connected; id = KLHEl1vQMzN8mX9S
I/System.out﹕ (VERBOSE): io.ably.transport.ConnectionManager: setState(): setting connected
V/ABLY CONNECTION CHANGE﹕ connected
I/System.out﹕ (VERBOSE): io.ably.realtime.Channel: RealtimeChannel(); channel = mobile:chat
I/System.out﹕ (VERBOSE): io.ably.realtime.Channel: attach(); channel = mobile:chat
I/System.out﹕ (VERBOSE): io.ably.realtime.Channel: setState(): channel = mobile:chat; setting attaching
I/System.out﹕ (VERBOSE): io.ably.realtime.Channel: subscribe(); channel = mobile:chat
I/System.out﹕ (VERBOSE): io.ably.realtime.Channel: attach(); channel = mobile:chat
D/libc﹕ [NET] android_getaddrinfofornet+,hn 16(0x7265616c74696d),sn(),hints(known),family 0,flags 4
D/libc﹕ [NET] android_getaddrinfofornet-, err=8
D/libc﹕ [NET] android_getaddrinfofornet+,hn 13(0x35342e39332e31),sn(),hints(known),family 0,flags 4
D/libc﹕ [NET] android_getaddrinfofornet-, SUCCESS
I/System.out﹕ (INFO): TokenAuth.getCredentials():
I/System.out﹕ (INFO): TokenAuth.authorise():
I/System.out﹕ (INFO): TokenAuth.authorise(): using cached token; expires = 1440689014722
W/System.err﹕ io.ably.types.AblyException: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.security.Principal.getName()' on a null object reference
W/System.err﹕ at io.ably.http.Http.getForHost(Unknown Source)
W/System.err﹕ at io.ably.http.Http.get(Unknown Source)
W/System.err﹕ at io.ably.http.PaginatedQuery.get(Unknown Source)
W/System.err﹕ at io.ably.realtime.Channel.history(Unknown Source)
W/System.err﹕ at com.example.stan.myapplication.MainActivity$1.onConnectionStateChanged(MainActivity.java:61)
W/System.err﹕ at io.ably.realtime.Connection.apply(Unknown Source)
W/System.err﹕ at io.ably.realtime.Connection.apply(Unknown Source)
W/System.err﹕ at io.ably.util.EventEmitter.emit(Unknown Source)
W/System.err﹕ at io.ably.realtime.Connection.onConnectionStateChange(Unknown Source)
W/System.err﹕ at io.ably.transport.ConnectionManager.setState(Unknown Source)
W/System.err﹕ at io.ably.transport.ConnectionManager.handleStateChange(Unknown Source)
W/System.err﹕ at io.ably.transport.ConnectionManager.run(Unknown Source)
W/System.err﹕ Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.security.Principal.getName()' on a null object reference
W/System.err﹕ at org.apache.http.impl.auth.BasicScheme.authenticate(BasicScheme.java:166)
W/System.err﹕ at org.apache.http.impl.auth.BasicScheme.authenticate(BasicScheme.java:142)
W/System.err﹕ at org.apache.http.client.protocol.RequestTargetAuthentication.process(RequestTargetAuthentication.java:96)
W/System.err﹕ at org.apache.http.protocol.BasicHttpProcessor.process(BasicHttpProcessor.java:290)
W/System.err﹕ at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:160)
W/System.err﹕ at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:420)
W/System.err﹕ at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
W/System.err﹕ ... 12 more
I/System.out﹕ (VERBOSE): io.ably.realtime.Channel: setAttached(); channel = mobile:chat
I/System.out﹕ (VERBOSE): io.ably.realtime.Channel: setState(): channel = mobile:chat; setting attached
I/System.out﹕ (VERBOSE): io.ably.realtime.Channel: sendQueuedMessages()
I/System.out﹕ (VERBOSE): io.ably.realtime.Channel: sendQueuedMessages()

FYI @mattheworiordan @paddybyers

stannedelchev commented 9 years ago

Any news regarding this issue? It's a blocker for history retrieval functionality in the Android demo app.

paddybyers commented 9 years ago

No, I've not had a chance yet but will asap

mattheworiordan commented 9 years ago

@stannedelchev we're doing our best to address this but just not had time. I'm hoping to get some help to address this in the next few days...

mattheworiordan commented 8 years ago

@stannedelchev can you test now as our Android work is merged in master. If this is still an issue, please tell us, and we'll prioritise

stannedelchev commented 8 years ago

@mattheworiordan I'll test it out on master today.

gokhanbarisaker commented 8 years ago

@stannedelchev I tested your code with ably-java v0.8.1

Although cause of exception is a bit little different since you are using an older version, I believe the reason is the same. We are receiving 82 a6 61 63 74 69 6f 6e 01 a5 63 6f 75 6e 74 01 messagepack message on the client. That translates to {"action":1,"count":1}. Since we are missing some required parameters (msgSerial in my case) by the client-side, that is throwing NPE.

@mattheworiordan How would you recommend us to handle this message?

Below you can find my NPE log

01-12 08:35:03.338 1865-1865/com.experiment.ablychannelhistorydemo I/System.out: (INFO): io.ably.lib.realtime.AblyRealtime: started
01-12 08:35:03.341 1865-1865/com.experiment.ablychannelhistorydemo I/System.out: (INFO): Auth(): using token auth with client-side signing
01-12 08:35:03.413 1865-1865/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.transport.ConnectionManager: requestState(): requesting connecting; id = null
01-12 08:35:03.414 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.transport.ConnectionManager: notifyState(): notifying connecting; id = null
01-12 08:35:03.415 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (INFO): TokenAuth.authorise(): 
01-12 08:35:03.415 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (INFO): TokenAuth.authorise(): requesting new token
01-12 08:35:03.415 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (INFO): Auth.requestToken(): using token auth with client-side signing
01-12 08:35:03.420 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (INFO): Auth.getTokenRequest(): generated signed request
01-12 08:35:03.422 1865-1921/com.experiment.ablychannelhistorydemo D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

                                                                                     [ 01-12 08:35:03.436  1865: 1865 D/         ]
                                                                                     HostConnection::get() New Host Connection established 0xf3fc5a80, tid 1865
01-12 08:35:03.443 1865-1865/com.experiment.ablychannelhistorydemo D/Atlas: Validating map...
01-12 08:35:03.501 1865-1921/com.experiment.ablychannelhistorydemo D/libEGL: loaded /system/lib/egl/libEGL_emulation.so
01-12 08:35:03.502 1865-1921/com.experiment.ablychannelhistorydemo D/libEGL: loaded /system/lib/egl/libGLESv1_CM_emulation.so
01-12 08:35:03.510 1865-1921/com.experiment.ablychannelhistorydemo D/libEGL: loaded /system/lib/egl/libGLESv2_emulation.so

                                                                             [ 01-12 08:35:03.515  1865: 1921 D/         ]
                                                                             HostConnection::get() New Host Connection established 0xeec394d0, tid 1921
01-12 08:35:03.538 1865-1921/com.experiment.ablychannelhistorydemo I/OpenGLRenderer: Initialized EGL, version 1.4
01-12 08:35:03.592 1865-1921/com.experiment.ablychannelhistorydemo D/OpenGLRenderer: Enabling debug mode 0
01-12 08:35:03.607 1865-1921/com.experiment.ablychannelhistorydemo W/EGL_emulation: eglSurfaceAttrib not implemented
01-12 08:35:03.607 1865-1921/com.experiment.ablychannelhistorydemo W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xeed48700, error=EGL_SUCCESS
01-12 08:35:05.437 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (INFO): TokenAuth.setTokenDetails(): 
01-12 08:35:05.437 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (INFO): TokenAuth.getTokenDetails(): 
01-12 08:35:05.438 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.transport.ConnectionManager: setState(): setting connecting
01-12 08:35:05.439 1865-1920/com.experiment.ablychannelhistorydemo V/ABLY CONNECTION CHANGE: connecting
01-12 08:35:06.130 1865-1956/com.experiment.ablychannelhistorydemo I/System.out: Unexpected field: serverId
01-12 08:35:06.130 1865-1956/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.transport.ConnectionManager: notifyState(): notifying connected; id = xoyyX2CeAQmA6Q6O-411e4300e
01-12 08:35:06.130 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.transport.ConnectionManager: setState(): setting connected
01-12 08:35:06.131 1865-1920/com.experiment.ablychannelhistorydemo V/ABLY CONNECTION CHANGE: connected
01-12 08:35:06.133 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.realtime.Channel: RealtimeChannel(); channel = mobile:chat
01-12 08:35:06.134 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.realtime.Channel: attach(); channel = mobile:chat
01-12 08:35:06.134 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.realtime.Channel: setState(): channel = mobile:chat; setting attaching
01-12 08:35:06.135 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.realtime.Channel: subscribe(); channel = mobile:chat
01-12 08:35:06.135 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.realtime.Channel: attach(); channel = mobile:chat
01-12 08:35:06.590 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (INFO): TokenAuth.authorise(): 
01-12 08:35:06.590 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (INFO): TokenAuth.authorise(): using cached token; expires = 1452609305169
01-12 08:35:06.590 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (INFO): TokenAuth.getEncodedToken(): 
01-12 08:35:08.249 1865-1956/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.realtime.Channel: setAttached(); channel = mobile:chat
01-12 08:35:08.249 1865-1956/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.realtime.Channel: setState(): channel = mobile:chat; setting attached
01-12 08:35:08.249 1865-1956/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.realtime.Channel: sendQueuedMessages()
01-12 08:35:08.250 1865-1956/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.realtime.Channel: sendQueuedMessages()
01-12 08:35:08.302 1865-1920/com.experiment.ablychannelhistorydemo V/ABLY TEST: History results: 0
01-12 08:35:08.302 1865-1920/com.experiment.ablychannelhistorydemo I/System.out: (VERBOSE): io.ably.lib.realtime.Channel: sync(); channel = mobile:chat
01-12 09:19:14.074 1865-1956/com.experiment.ablychannelhistorydemo I/System.out: (ERROR): io.ably.lib.transport.WebSocketTransport: Unexpected exception in WsClient
01-12 09:19:14.074 1865-1956/com.experiment.ablychannelhistorydemo I/System.out: java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference
01-12 09:19:14.074 1865-1956/com.experiment.ablychannelhistorydemo I/System.out:     at io.ably.lib.transport.ConnectionManager.onAck(ConnectionManager.java:342)
01-12 09:19:14.074 1865-1956/com.experiment.ablychannelhistorydemo I/System.out:     at io.ably.lib.transport.ConnectionManager.onMessage(ConnectionManager.java:287)
01-12 09:19:14.074 1865-1956/com.experiment.ablychannelhistorydemo I/System.out:     at io.ably.lib.transport.WebSocketTransport$WsClient.onMessage(WebSocketTransport.java:148)
01-12 09:19:14.074 1865-1956/com.experiment.ablychannelhistorydemo I/System.out:     at org.java_websocket.client.WebSocketClient.onWebsocketMessage(WebSocketClient.java:253)
01-12 09:19:14.074 1865-1956/com.experiment.ablychannelhistorydemo I/System.out:     at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:381)
01-12 09:19:14.074 1865-1956/com.experiment.ablychannelhistorydemo I/System.out:     at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:158)
01-12 09:19:14.075 1865-1956/com.experiment.ablychannelhistorydemo I/System.out:     at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:185)
01-12 09:19:14.075 1865-1956/com.experiment.ablychannelhistorydemo I/System.out:     at java.lang.Thread.run(Thread.java:818)
paddybyers commented 8 years ago

How would you recommend us to handle this message?

You should not crash but there isn't anything else really you should do, because it should never be possible for you to receive this message. I will have a look at why this is being sent.

gokhanbarisaker commented 8 years ago

You should not crash

OK. I will handle the exception.

mattheworiordan commented 8 years ago

Thanks @gokhanbarisaker for identifying this, looks like we have a bug in the realtime system. I have raised an issue that will hopefully be fixed shortly by @paddybyers