-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1237 from bugsnag/PLAT-6493/fix-thread-capture-npe
Prevent rare NPE when capturing thread traces
- Loading branch information
Showing
3 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
bugsnag-android-core/src/test/java/com/bugsnag/android/ThreadStateMissingTraceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.bugsnag.android | ||
|
||
import org.junit.Assert.assertNotNull | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
import java.lang.RuntimeException | ||
import java.lang.Thread | ||
import java.util.Collections | ||
|
||
class ThreadStateMissingTraceTest { | ||
|
||
@Test | ||
fun handleNullThreadTraces() { | ||
val currentThread = Thread.currentThread() | ||
val traces = Thread.getAllStackTraces() | ||
|
||
// make all stacktraces null | ||
traces.keys.forEach { | ||
traces[it] = null | ||
} | ||
|
||
val state = ThreadState( | ||
RuntimeException(), | ||
false, | ||
ThreadSendPolicy.ALWAYS, | ||
Collections.emptyList(), | ||
NoopLogger, | ||
currentThread, | ||
traces | ||
) | ||
assertNotNull(state) | ||
assertTrue(state.threads.isEmpty()) | ||
} | ||
} |