Skip to content

Commit 7ec1e5a

Browse files
authored
Merge pull request #49 from MindscapeHQ/md/sup-330/fix-null-reference
[SUP-330] Guard against accessing null objects
2 parents 4054f33 + a64519f commit 7ec1e5a

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

sdk/android/src/main/java/com/raygun/react/RaygunNativeBridgeModule.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ public void initRealUserMonitoringNativeSupport() {
126126
//Cant initialise bridge rum twice
127127
if (realUserMonitoringInitialized) return;
128128

129-
if (reactContext.getCurrentActivity() != null) {
129+
if (reactContext != null && reactContext.getCurrentActivity() != null) {
130130
//Store the current activity to differentiate session changes
131131
currentActivity = new WeakReference<>(reactContext.getCurrentActivity());
132132
//Attach the activity listening logic to the Application
133133
reactContext.getCurrentActivity().getApplication().registerActivityLifecycleCallbacks(this);
134-
} else Log.e("TAG", "This react application has no active activity");
134+
} else Log.e("Raygun", "This react application has no active activity");
135135

136136
realUserMonitoringInitialized = true;
137137
}
@@ -186,16 +186,21 @@ public void onActivityStarted(Activity activity) {
186186
public void onActivityResumed(Activity activity) {
187187
//If the activity that recently paused is returning to the foreground then the whole
188188
// application has resumed, therefore update the session
189-
if (currentActivity.get() == activity) this.sendJSEvent(ON_SESSION_RESUME, null);
190-
189+
if (currentActivity != null && currentActivity.get() == activity) {
190+
this.sendJSEvent(ON_SESSION_RESUME, null);
191+
}
192+
else {
191193
//If any other activity resumes that means that it is taking over from the current activity
192-
else currentActivity = new WeakReference<>(activity);
194+
currentActivity = new WeakReference<>(activity);
195+
}
193196
}
194197

195198
@Override
196199
public void onActivityPaused(Activity activity) {
197200
//If the current activity is pausing then the session is paused
198-
if (currentActivity.get() == activity) this.sendJSEvent(ON_SESSION_PAUSE, null);
201+
if (currentActivity != null && currentActivity.get() == activity) {
202+
this.sendJSEvent(ON_SESSION_PAUSE, null);
203+
}
199204
}
200205

201206
@Override
@@ -208,7 +213,7 @@ public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
208213

209214
@Override
210215
public void onActivityDestroyed(Activity activity) {
211-
if (currentActivity.get() == activity) {
216+
if (currentActivity != null && currentActivity.get() == activity) {
212217
this.sendJSEvent(ON_SESSION_END, null);
213218
currentActivity = null;
214219
}

sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "raygun4reactnative",
33
"title": "Raygun4reactnative",
4-
"version": "1.1.4",
4+
"version": "1.1.5",
55
"description": "Raygun React Native SDK",
66
"main": "dist/index.js",
77
"typescript": {

0 commit comments

Comments
 (0)