Skip to content

Commit 43f2eaa

Browse files
committed
Removed finally block that closes ably client, instead used try with resources
1 parent a0354e5 commit 43f2eaa

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

lib/src/main/java/io/ably/lib/realtime/Presence.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ private void implicitAttachOnSubscribe(CompletionListener completionListener) th
305305
// RTP6e
306306
if (!channel.attachOnSubscribeEnabled()) {
307307
if (completionListener != null) {
308-
String errorString = String.format(Locale.ROOT,
308+
String errorString = String.format(
309309
"Channel %s: attachOnSubscribe=false doesn't expect attach completion callback", channel.name);
310310
Log.e(TAG, errorString);
311311
ErrorInfo errorInfo = new ErrorInfo(errorString, 400,40000);

lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceTest.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,14 +1692,11 @@ public void presence_subscribe_without_implicit_attach() {
16921692
* @throws AblyException
16931693
*/
16941694
@Test
1695-
public void presence_subscribe_without_implicit_attach_and_completion_listener_throws_exception() {
1695+
public void presence_subscribe_without_implicit_attach_and_completion_listener_throws_exception() throws AblyException {
16961696
String ablyChannel = "subscribe_" + testParams.name;
1697-
AblyRealtime ably = null;
1698-
try {
1699-
ClientOptions option1 = createOptions(testVars.keys[0].keyStr);
1700-
option1.clientId = "client1";
1701-
ably = new AblyRealtime(option1);
1702-
1697+
ClientOptions option1 = createOptions(testVars.keys[0].keyStr);
1698+
option1.clientId = "client1";
1699+
try (AblyRealtime ably = new AblyRealtime(option1)) {
17031700
/* create a channel and set attachOnSubscribe to false */
17041701
final Channel channel = ably.channels.get(ablyChannel);
17051702
ChannelOptions chOpts = new ChannelOptions();
@@ -1720,9 +1717,6 @@ public void presence_subscribe_without_implicit_attach_and_completion_listener_t
17201717
} catch (AblyException e) {
17211718
e.printStackTrace();
17221719
fail("presence_subscribe_without_implicit_attach: Unexpected exception");
1723-
} finally {
1724-
if(ably != null)
1725-
ably.close();
17261720
}
17271721
}
17281722

0 commit comments

Comments
 (0)