From 6dd4461a2e5a705408ae00add4fafae96eeded7b Mon Sep 17 00:00:00 2001 From: evgeny Date: Tue, 21 Nov 2023 23:36:50 +0000 Subject: [PATCH 1/4] feat: throw exception when trying to attach on released channel --- .../io/ably/lib/realtime/AblyRealtime.java | 1 + .../io/ably/lib/realtime/ChannelBase.java | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/io/ably/lib/realtime/AblyRealtime.java b/lib/src/main/java/io/ably/lib/realtime/AblyRealtime.java index ffb33d426..34098ea0b 100644 --- a/lib/src/main/java/io/ably/lib/realtime/AblyRealtime.java +++ b/lib/src/main/java/io/ably/lib/realtime/AblyRealtime.java @@ -206,6 +206,7 @@ public Channel get(final String channelName, final ChannelOptions channelOptions public void release(String channelName) { Channel channel = map.remove(channelName); if(channel != null) { + channel.markAsReleased(); try { channel.detach(); } catch (AblyException e) { diff --git a/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java b/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java index 1da00e9ba..4163876c3 100644 --- a/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java +++ b/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java @@ -83,6 +83,13 @@ public abstract class ChannelBase extends EventEmitter Date: Thu, 23 Nov 2023 10:00:28 +0000 Subject: [PATCH 2/4] chore: sneaky throw AblyException --- lib/src/main/java/io/ably/lib/realtime/ChannelBase.java | 7 ++----- lib/src/main/java/io/ably/lib/util/Exceptions.java | 7 +++++++ 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 lib/src/main/java/io/ably/lib/util/Exceptions.java diff --git a/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java b/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java index 4163876c3..a9c170509 100644 --- a/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java +++ b/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java @@ -33,10 +33,7 @@ import io.ably.lib.types.ProtocolMessage; import io.ably.lib.types.ProtocolMessage.Action; import io.ably.lib.types.ProtocolMessage.Flag; -import io.ably.lib.util.CollectionUtils; -import io.ably.lib.util.EventEmitter; -import io.ably.lib.util.Log; -import io.ably.lib.util.ReconnectionStrategy; +import io.ably.lib.util.*; /** * Enables messages to be published and subscribed to. @@ -507,7 +504,7 @@ public void run() { } private void checkChannelIsNotReleased() { - if (released) throw new IllegalStateException("Can't perform any operation on released channel"); + if (released) Exceptions.sneakyThrow(AblyException.fromErrorInfo(new ErrorInfo("Unable to perform any operation on released channel", 90001))); } /** diff --git a/lib/src/main/java/io/ably/lib/util/Exceptions.java b/lib/src/main/java/io/ably/lib/util/Exceptions.java new file mode 100644 index 000000000..fc69b6f23 --- /dev/null +++ b/lib/src/main/java/io/ably/lib/util/Exceptions.java @@ -0,0 +1,7 @@ +package io.ably.lib.util; + +public class Exceptions { + public static void sneakyThrow(Throwable e) throws E { + throw (E) e; + } +} From 4082a25cfc44a5868564eef91963358e2070fc98 Mon Sep 17 00:00:00 2001 From: evgeny Date: Thu, 23 Nov 2023 10:16:57 +0000 Subject: [PATCH 3/4] fix: linter --- lib/src/main/java/io/ably/lib/realtime/ChannelBase.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java b/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java index a9c170509..ec12966fc 100644 --- a/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java +++ b/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java @@ -33,7 +33,11 @@ import io.ably.lib.types.ProtocolMessage; import io.ably.lib.types.ProtocolMessage.Action; import io.ably.lib.types.ProtocolMessage.Flag; -import io.ably.lib.util.*; +import io.ably.lib.util.CollectionUtils; +import io.ably.lib.util.EventEmitter; +import io.ably.lib.util.Log; +import io.ably.lib.util.ReconnectionStrategy; +import io.ably.lib.util.Exceptions; /** * Enables messages to be published and subscribed to. From df5bd4a0b6d4a9fa3330bd7ee01924639e467cb2 Mon Sep 17 00:00:00 2001 From: evgeny Date: Thu, 23 Nov 2023 12:31:47 +0000 Subject: [PATCH 4/4] Revert "chore: sneaky throw AblyException" This reverts commit 002613e2 --- lib/src/main/java/io/ably/lib/realtime/ChannelBase.java | 3 +-- lib/src/main/java/io/ably/lib/util/Exceptions.java | 7 ------- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 lib/src/main/java/io/ably/lib/util/Exceptions.java diff --git a/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java b/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java index ec12966fc..326e773f1 100644 --- a/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java +++ b/lib/src/main/java/io/ably/lib/realtime/ChannelBase.java @@ -37,7 +37,6 @@ import io.ably.lib.util.EventEmitter; import io.ably.lib.util.Log; import io.ably.lib.util.ReconnectionStrategy; -import io.ably.lib.util.Exceptions; /** * Enables messages to be published and subscribed to. @@ -508,7 +507,7 @@ public void run() { } private void checkChannelIsNotReleased() { - if (released) Exceptions.sneakyThrow(AblyException.fromErrorInfo(new ErrorInfo("Unable to perform any operation on released channel", 90001))); + if (released) throw new IllegalStateException("Unable to perform any operation on released channel"); } /** diff --git a/lib/src/main/java/io/ably/lib/util/Exceptions.java b/lib/src/main/java/io/ably/lib/util/Exceptions.java deleted file mode 100644 index fc69b6f23..000000000 --- a/lib/src/main/java/io/ably/lib/util/Exceptions.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.ably.lib.util; - -public class Exceptions { - public static void sneakyThrow(Throwable e) throws E { - throw (E) e; - } -}