From f6fdc23744f661e1761ca8ee293f7f692d16a910 Mon Sep 17 00:00:00 2001 From: Kacper Kluka Date: Thu, 17 Nov 2022 12:44:14 +0100 Subject: [PATCH] Fix NPE from Ably CompletionListeners --- .../java/com/ably/tracking/common/Ably.kt | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/com/ably/tracking/common/Ably.kt b/common/src/main/java/com/ably/tracking/common/Ably.kt index d869642e1..b8263a655 100644 --- a/common/src/main/java/com/ably/tracking/common/Ably.kt +++ b/common/src/main/java/com/ably/tracking/common/Ably.kt @@ -453,8 +453,11 @@ constructor( continuation.resume(Unit) } - override fun onError(reason: ErrorInfo) { - continuation.resumeWithException(reason.toTrackingException()) + override fun onError(reason: ErrorInfo?) { + continuation.resumeWithException( + reason?.toTrackingException() + ?: ConnectionException(ErrorInformation("Unknown error when leaving presence ${channel.name}")) + ) } } ) @@ -545,8 +548,11 @@ constructor( continuation.resume(Unit) } - override fun onError(reason: ErrorInfo) { - continuation.resumeWithException(reason.toTrackingException()) + override fun onError(reason: ErrorInfo?) { + continuation.resumeWithException( + reason?.toTrackingException() + ?: ConnectionException(ErrorInformation("Unknown error when sending message ${channel.name}")) + ) } } ) @@ -720,8 +726,11 @@ constructor( continuation.resume(Unit) } - override fun onError(reason: ErrorInfo) { - continuation.resumeWithException(reason.toTrackingException()) + override fun onError(reason: ErrorInfo?) { + continuation.resumeWithException( + reason?.toTrackingException() + ?: ConnectionException(ErrorInformation("Unknown error when updating presence ${channel.name}")) + ) } } ) @@ -870,8 +879,11 @@ constructor( continuation.resume(Unit) } - override fun onError(reason: ErrorInfo) { - continuation.resumeWithException(reason.toTrackingException()) + override fun onError(reason: ErrorInfo?) { + continuation.resumeWithException( + reason?.toTrackingException() + ?: ConnectionException(ErrorInformation("Unknown error when entering presence $name")) + ) } } ) @@ -893,8 +905,11 @@ constructor( continuation.resume(Unit) } - override fun onError(reason: ErrorInfo) { - continuation.resumeWithException(reason.toTrackingException()) + override fun onError(reason: ErrorInfo?) { + continuation.resumeWithException( + reason?.toTrackingException() + ?: ConnectionException(ErrorInformation("Unknown error when attaching channel $name")) + ) } }) } catch (ablyException: AblyException) {