Skip to content

Commit ded0be2

Browse files
fix(perf, android): gracefully handle metric/trace/screentrace nulls during module teardown (#8946)
1 parent 54021c4 commit ded0be2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/perf/android/src/main/java/io/invertase/firebase/perf/UniversalFirebasePerfModule.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ Task<Void> stopTrace(int id, Bundle metrics, Bundle attributes) {
8383
return Tasks.call(
8484
() -> {
8585
Trace trace = traces.get(id);
86+
// Traces can be cleared during module teardown before JS stops them.
87+
if (trace == null) {
88+
return null;
89+
}
8690

8791
Set<String> metricKeys = metrics.keySet();
8892
Set<String> attributeKeys = attributes.keySet();
@@ -119,6 +123,10 @@ Task<Void> stopScreenTrace(int id) {
119123
return Tasks.call(
120124
() -> {
121125
ScreenTrace trace = screenTraces.get(id);
126+
// Screen traces can be cleared during module teardown before JS stops them.
127+
if (trace == null) {
128+
return null;
129+
}
122130
trace.sendScreenTrace();
123131
screenTraces.remove(id);
124132

@@ -140,6 +148,10 @@ Task<Void> stopHttpMetric(int id, Bundle httpMetricConfig, Bundle attributes) {
140148
return Tasks.call(
141149
() -> {
142150
HttpMetric httpMetric = httpMetrics.get(id);
151+
// HTTP metrics can be cleared during module teardown before JS stops them.
152+
if (httpMetric == null) {
153+
return null;
154+
}
143155

144156
if (httpMetricConfig.containsKey("httpResponseCode")) {
145157
httpMetric.setHttpResponseCode((int) httpMetricConfig.getDouble("httpResponseCode"));

0 commit comments

Comments
 (0)