ably-java icon indicating copy to clipboard operation
ably-java copied to clipboard

NullPointerException When Attempting to read from field 'java.lang.String io.ably.lib.types.ErrorInfo.message'

Open migueledgracia opened this issue 1 year ago β€’ 12 comments

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)

┆Issue is synchronized with this Jira Task by Unito

migueledgracia avatar Mar 22 '24 03:03 migueledgracia

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

sacOO7 avatar Mar 22 '24 04:03 sacOO7

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.

migueledgracia avatar Mar 22 '24 04:03 migueledgracia

Okay, we will check and get back to you πŸ‘

sacOO7 avatar Mar 22 '24 05:03 sacOO7

Thank you @sacOO7

migueledgracia avatar Mar 22 '24 05:03 migueledgracia

Ideally, this problem shouldn't occur. I had some more questions related to this

  1. Are you using this library on android ?
  2. Does it go through disconnected or suspended states frequently?
  3. It will be great if we have verbose logs before the crash ( to detect changes in connection states )

sacOO7 avatar Mar 22 '24 05:03 sacOO7

@sacOO7

  1. yes I'm using it in Android
  2. We do call AblyRealtime.close() every time the user sends their app into the background and AblyRealtime.connection.connect() when the app comes to the foreground, although there are some circumstances on which we might call AblyRealtime.connection.connect() more often, like when we get notify that the user phone has regain internet connectivity after loosing it.
  3. I have attached the logs to this comment ably crash.log

migueledgracia avatar Mar 22 '24 06:03 migueledgracia

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.

sacOO7 avatar Mar 22 '24 07:03 sacOO7

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.

migueledgracia avatar Mar 22 '24 07:03 migueledgracia

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 ).

sacOO7 avatar Mar 22 '24 07:03 sacOO7

@migueledgracia we will check to implement fix for this πŸ‘. Till then, you can go with creating a new instance of ably for now

sacOO7 avatar Mar 22 '24 07:03 sacOO7

Thanks @sacOO7

migueledgracia avatar Mar 22 '24 17:03 migueledgracia

@migueledgracia let me know if the exception still occurs. Ideally it shouldn't occur πŸ‘

sacOO7 avatar Apr 03 '24 14:04 sacOO7

closing issue. @migueledgracia let us know if you face any further issues

jamienewcomb avatar May 09 '24 12:05 jamienewcomb