Skip to content
Closed
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
30 changes: 24 additions & 6 deletions sentry/src/main/java/io/sentry/SentryExceptionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,20 @@ public List<SentryException> getSentryExceptions(final @NotNull Throwable throwa
@NotNull
Deque<SentryException> extractExceptionQueue(final @NotNull Throwable throwable) {
return extractExceptionQueueInternal(
throwable, new AtomicInteger(-1), new HashSet<>(), new ArrayDeque<>());
throwable, new AtomicInteger(-1), new HashSet<>(), new ArrayDeque<>(), null);
}

Deque<SentryException> extractExceptionQueueInternal(
final @NotNull Throwable throwable,
final @NotNull AtomicInteger exceptionId,
final @NotNull HashSet<Throwable> circularityDetector,
final @NotNull Deque<SentryException> exceptions) {
final @NotNull Deque<SentryException> exceptions,
final @Nullable Integer parentIdOverride) {
Mechanism exceptionMechanism;
Thread thread;

Throwable currentThrowable = throwable;
int parentId = exceptionId.get();
int parentId = parentIdOverride == null ? exceptionId.get() : parentIdOverride;

// Stack the exceptions to send them in the reverse order
while (currentThrowable != null && circularityDetector.add(currentThrowable)) {
Expand All @@ -167,6 +168,21 @@ Deque<SentryException> extractExceptionQueueInternal(
thread = Thread.currentThread();
}

if (currentThrowable instanceof SentryExceptionGroupException) {
exceptionMechanism.setExceptionGroup(true);
}

Throwable[] suppressed = currentThrowable.getSuppressed();
if (suppressed != null && suppressed.length > 0) {
extractExceptionQueueInternal(
new SentryExceptionGroupException(),
exceptionId,
circularityDetector,
exceptions,
null);
parentId = exceptionId.get();
}

final boolean includeSentryFrames = Boolean.FALSE.equals(exceptionMechanism.isHandled());
final List<SentryStackFrame> frames =
sentryStackTraceFactory.getStackFrames(
Expand All @@ -187,12 +203,10 @@ Deque<SentryException> extractExceptionQueueInternal(
final int currentExceptionId = exceptionId.incrementAndGet();
exceptionMechanism.setExceptionId(currentExceptionId);

Throwable[] suppressed = currentThrowable.getSuppressed();
if (suppressed != null && suppressed.length > 0) {
exceptionMechanism.setExceptionGroup(true);
for (Throwable suppressedThrowable : suppressed) {
extractExceptionQueueInternal(
suppressedThrowable, exceptionId, circularityDetector, exceptions);
suppressedThrowable, exceptionId, circularityDetector, exceptions, parentId);
}
}
currentThrowable = currentThrowable.getCause();
Expand All @@ -201,4 +215,8 @@ Deque<SentryException> extractExceptionQueueInternal(

return exceptions;
}

private static final class SentryExceptionGroupException extends RuntimeException {
private static final long serialVersionUID = 6909700354645201267L;
}
}
Loading