Skip to content

Commit

Permalink
Merge pull request #2083 from bugsnag/PLAT-12834/ActivityBreadcrumbCo…
Browse files Browse the repository at this point in the history
…llectorFix

Work around NPEs from `Intent.getExtras`
  • Loading branch information
lemnik authored Sep 30, 2024
2 parents 8074d55 + c88f726 commit 9f2add0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* Sending startup crashes synchronously now uses a flexible timeout so that apps with slower startups don't ANR
[#2075](https://github.com/bugsnag/bugsnag-android/pull/2075)
[#2080](https://github.com/bugsnag/bugsnag-android/pull/2080)
* Work around a possible platform NullPointerException when calling `Intent.getExtras` (https://github.com/bugsnag/bugsnag-android/issues/2082)
[#2083](https://github.com/bugsnag/bugsnag-android/pull/2083)

## 6.7.0 (2024-08-08)

Expand Down
1 change: 1 addition & 0 deletions bugsnag-android-core/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<ID>ProtectedMemberInFinalClass:EventInternal.kt$EventInternal$protected fun updateSeverityReason(@SeverityReason.SeverityReasonType reason: String)</ID>
<ID>ReturnCount:DefaultDelivery.kt$DefaultDelivery$fun deliver( urlString: String, json: ByteArray, headers: Map&lt;String, String?> ): DeliveryStatus</ID>
<ID>SpreadOperator:FileStore.kt$FileStore$(*listFiles)</ID>
<ID>SwallowedException:ActivityBreadcrumbCollector.kt$ActivityBreadcrumbCollector$re: Exception</ID>
<ID>SwallowedException:AppDataCollector.kt$AppDataCollector$e: Exception</ID>
<ID>SwallowedException:BugsnagEventMapper.kt$BugsnagEventMapper$pe: IllegalArgumentException</ID>
<ID>SwallowedException:ConnectivityCompat.kt$ConnectivityLegacy$e: NullPointerException</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ internal class ActivityBreadcrumbCollector(
}

set("hasData", intent.data != null)
set("hasExtras", intent.extras?.keySet()?.joinToString(", ") ?: false)

try {
set("hasExtras", intent.extras?.keySet()?.joinToString(", ") ?: false)
} catch (re: Exception) {
// deliberately ignore
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bugsnag.android

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
Expand All @@ -10,6 +11,8 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.mock
import org.mockito.Mockito.`when`
import org.mockito.junit.MockitoJUnitRunner

@RunWith(MockitoJUnitRunner::class)
Expand Down Expand Up @@ -120,4 +123,15 @@ internal class ActivityLifecycleBreadcrumbTest {
tracker.onActivityStarted(activity2)
assertEquals("onCreate()", resultMetadata!!["previous"])
}

@Test
fun failGetExtras() {
val mockIntent = mock(Intent::class.java)
`when`(mockIntent.extras).thenThrow(NullPointerException())
`when`(activity.intent).thenReturn(mockIntent)

tracker.onActivityCreated(activity, null)
assertFalse(resultMetadata!!["hasBundle"] as Boolean)
assertFalse(resultMetadata!!["hasData"] as Boolean)
}
}

0 comments on commit 9f2add0

Please sign in to comment.