Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
[173523] Check for nulls when calling getLastXXX (#157)
Browse files Browse the repository at this point in the history
This is a bugfix for the publicly submitted issue:
#160

where `getLastSuccessfulConnection` and `getLastFailedConnection` can
result in a null exception.

---------

Co-authored-by: Yusinto Ngadiman <yus@launchdarkly.com>
  • Loading branch information
yusinto and yusinto authored Jun 20, 2023
1 parent 089e8a7 commit 13b1544
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.launchdarkly.sdk.android.LDConfig;
import com.launchdarkly.sdk.android.LDFailure;
import com.launchdarkly.sdk.android.LDStatusListener;
import com.launchdarkly.sdk.android.LaunchDarklyException;
import com.launchdarkly.sdk.android.integrations.ApplicationInfoBuilder;
import com.launchdarkly.sdk.android.integrations.EventProcessorBuilder;
import com.launchdarkly.sdk.android.integrations.HttpConfigurationBuilder;
Expand Down Expand Up @@ -636,7 +635,12 @@ public void getConnectionMode(String environment, Promise promise) {
@ReactMethod
public void getLastSuccessfulConnection(String environment, Promise promise) {
try {
promise.resolve(LDClient.getForMobileKey(environment).getConnectionInformation().getLastSuccessfulConnection().intValue());
Long lastSuccessfulConnection = LDClient.getForMobileKey(environment).getConnectionInformation().getLastSuccessfulConnection();
if (lastSuccessfulConnection != null) {
promise.resolve(lastSuccessfulConnection.doubleValue());
} else {
promise.resolve(null);
}
} catch (Exception e) {
Timber.w(e, "Warning: exception caught in getLastSuccessfulConnection");
promise.resolve(0);
Expand All @@ -646,7 +650,13 @@ public void getLastSuccessfulConnection(String environment, Promise promise) {
@ReactMethod
public void getLastFailedConnection(String environment, Promise promise) {
try {
promise.resolve(LDClient.getForMobileKey(environment).getConnectionInformation().getLastFailedConnection().intValue());
Long lastFailedConnection = LDClient.getForMobileKey(environment).getConnectionInformation().getLastFailedConnection();
if (lastFailedConnection != null) {
promise.resolve(lastFailedConnection.doubleValue());
} else {
promise.resolve(null);
}

} catch (Exception e) {
Timber.w(e, "Warning: exception caught in getLastFailedConnection");
promise.resolve(0);
Expand Down

0 comments on commit 13b1544

Please sign in to comment.