Skip to content

Commit

Permalink
Added explicit null checks for recoveryKey
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Nov 28, 2023
1 parent e7dc410 commit 130305b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/src/main/java/io/ably/lib/realtime/AblyRealtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.ably.lib.types.*;
import io.ably.lib.util.InternalMap;
import io.ably.lib.util.Log;
import io.ably.lib.util.StringUtils;

/**
* A client that extends the functionality of the {@link AblyRest} and provides additional realtime-specific features.
Expand Down Expand Up @@ -66,7 +67,7 @@ public void onConnectionStateChanged(ConnectionStateListener.ConnectionStateChan
}
});

if (options.recover != null && !options.recover.isEmpty()) {
if (!StringUtils.isNullOrEmpty(options.recover)) {
RecoveryKeyContext recoveryKeyContext = RecoveryKeyContext.decode(options.recover);
if (recoveryKeyContext != null) {
setChannelSerialsFromRecoverOption(recoveryKeyContext.getChannelSerials());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.ably.lib.util.Log;
import io.ably.lib.util.PlatformAgentProvider;
import io.ably.lib.util.ReconnectionStrategy;
import io.ably.lib.util.StringUtils;

public class ConnectionManager implements ConnectListener {
final ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
Expand Down Expand Up @@ -1202,6 +1203,10 @@ private synchronized void onConnected(ProtocolMessage message) {
boolean reattachOnResumeFailure = false; // this will indicate that channel must reattach when connected
// event is received

boolean isConnectionResumeOrRecoverAttempt = !StringUtils.isNullOrEmpty(connection.key) ||
!StringUtils.isNullOrEmpty(ably.options.recover);
ably.options.recover = null; // RTN16k, explicitly setting null, so it won't be used for subsequent connection requests

connection.reason = error;
if (connection.id != null) { // there was a previous connection, so this is a resume and RTN15c applies
Log.d(TAG, "There was a connection resume");
Expand Down
5 changes: 3 additions & 2 deletions lib/src/main/java/io/ably/lib/transport/ITransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.ably.lib.util.AgentHeaderCreator;
import io.ably.lib.util.Log;
import io.ably.lib.util.PlatformAgentProvider;
import io.ably.lib.util.StringUtils;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -61,10 +62,10 @@ public Param[] getConnectParams(Param[] baseParams) {
paramList.add(new Param("format", (options.useBinaryProtocol ? "msgpack" : "json")));
if(!options.echoMessages)
paramList.add(new Param("echo", "false"));
if(connectionKey != null) {
if(!StringUtils.isNullOrEmpty(connectionKey)) {
mode = Mode.resume;
paramList.add(new Param("resume", connectionKey));
} else if(options.recover != null && !options.recover.isEmpty()) { // RTN16k
} else if(!StringUtils.isNullOrEmpty(options.recover)) { // RTN16k
mode = Mode.recover;
RecoveryKeyContext recoveryKeyContext = RecoveryKeyContext.decode(options.recover);
if (recoveryKeyContext != null) {
Expand Down
5 changes: 5 additions & 0 deletions lib/src/main/java/io/ably/lib/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import io.ably.lib.http.HttpCore;

public class StringUtils {

public static boolean isNullOrEmpty(String value) {
return value == null || value.isEmpty();
}

public static Serialisation.FromJsonElement<String> fromJsonElement = new Serialisation.FromJsonElement<String>() {
@Override
public String fromJsonElement(JsonElement e) {
Expand Down

0 comments on commit 130305b

Please sign in to comment.