NullPointerException When Attempting to read from field 'java.lang.String io.ably.lib.types.ErrorInfo.message'
Caused by: java.lang.NullPointerException: Attempt to read from field 'java.lang.String io.ably.lib.types.ErrorInfo.message' on a null object reference in method 'io.ably.lib.types.AblyException io.ably.lib.types.AblyException.fromErrorInfo(io.ably.lib.types.ErrorInfo)' io.ably.lib.realtime.ChannelBase.attachImpl(ChannelBase.java:240) io.ably.lib.realtime.ChannelBase.attachWithTimeout(ChannelBase.java:470) io.ably.lib.realtime.ChannelBase.attach(ChannelBase.java:196) io.ably.lib.realtime.ChannelBase.attach(ChannelBase.java:191) io.ably.lib.realtime.ChannelBase.attach(ChannelBase.java:173) io.ably.lib.realtime.ChannelBase.subscribe(ChannelBase.java:707)
Hi @migueledgracia how likely does this exception error occur ? What version of ably-java are you using? Is this started happening recently or it used to work before? Can you also try to log connection state while this error occurs
Hi @sacOO7, this crash is new for us, we recently upgraded from v1.0.10 to v1.2.35, we made a release that contain the updated Ably library to production three days ago and we had a total of 32 crashes so far caused by it.
Okay, we will check and get back to you π
Thank you @sacOO7
Ideally, this problem shouldn't occur. I had some more questions related to this
- Are you using this library on android ?
- Does it go through
disconnectedorsuspendedstates frequently? - It will be great if we have verbose logs before the crash ( to detect changes in connection states )
@sacOO7
- yes I'm using it in Android
- We do call
AblyRealtime.close()every time the user sends their app into the background andAblyRealtime.connection.connect()when the app comes to the foreground, although there are some circumstances on which we might callAblyRealtime.connection.connect()more often, like when we get notify that the user phone has regain internet connectivity after loosing it. - I have attached the logs to this comment ably crash.log
Hi @migueledgracia, actually you don't need to handle reconnection mechanism explicitly. ably-java will automatically handle it for you. You can provide clientOption to provide reconnect timeout using disconnectedRetryTimeout and suspendedRetryTimeout. Though this will also include to removing custom code that handles close and connect mechanism.
i.e.
final realtime = Realtime(
options: ClientOptions(
disconnectedRetryTimeout: 5000,
suspendedRetryTimeout: 5000,
),
);
basically client goes into disconnected state, keeps retrying for 2 minutes, then goes into suspended state and keeps retrying indefinitely. Timeout between those retries is given by above timeout values.
Thanks @sacOO7, right now our app needs to disconnect from AblyRealtime when our app is put in the background, so our backend can send us push notifications through FCM, we haven't link FCM with our Ably account, this is because our implementation for Android and the backend is pretty old.
Ohkay, got it. Then can you do one thing. You create a new instance of ably when app comes back from background to foreground.
~This would include storing recoveryKey from previous instance before calling close().~
seems when you call close, no connections state is preserved by service or the SDK. So, recovery will not work in this case ( didn't work before either ).
@migueledgracia we will check to implement fix for this π. Till then, you can go with creating a new instance of ably for now
Thanks @sacOO7
@migueledgracia let me know if the exception still occurs. Ideally it shouldn't occur π
closing issue. @migueledgracia let us know if you face any further issues