Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

set current threadId when theres no mechanism to rely on #277

Merged
merged 2 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Deque<SentryException> extractExceptionQueue(final @NotNull Throwable throwable)
thread = exceptionMechanismThrowable.getThread();
} else {
exceptionMechanism = null;
thread = null;
thread = Thread.currentThread();
}

SentryException exception = getSentryException(currentThrowable, exceptionMechanism, thread);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,27 @@ class SentryExceptionFactoryTest {
assertEquals("SentryExceptionFactoryTest\$InnerClassThrowable", queue.first.type)
}

@Test
fun `when exception has no mechanism, it should get and set the current threadId`() {
val threadId = Thread.currentThread().id
val exception = Exception("message", Exception("cause"))
val queue = sut.extractExceptionQueue(exception)

assertEquals(threadId, queue.first.threadId)
}

@Test
fun `when exception has a mechanism, it should get and set the mechanism's threadId`() {
val exception = Exception("message")
val mechanism = Mechanism()
mechanism.type = "ANR"
val thread = Thread()
val throwable = ExceptionMechanismException(mechanism, exception, thread)

val queue = sut.extractExceptionQueue(throwable)

assertEquals(thread.id, queue.first.threadId)
}

private inner class InnerClassThrowable constructor(cause: Throwable? = null) : Throwable(cause)
}