@@ -137,19 +137,20 @@ public List<SentryException> getSentryExceptions(final @NotNull Throwable throwa
137137 @ NotNull
138138 Deque <SentryException > extractExceptionQueue (final @ NotNull Throwable throwable ) {
139139 return extractExceptionQueueInternal (
140- throwable , new AtomicInteger (-1 ), new HashSet <>(), new ArrayDeque <>());
140+ throwable , new AtomicInteger (-1 ), new HashSet <>(), new ArrayDeque <>(), null );
141141 }
142142
143143 Deque <SentryException > extractExceptionQueueInternal (
144144 final @ NotNull Throwable throwable ,
145145 final @ NotNull AtomicInteger exceptionId ,
146146 final @ NotNull HashSet <Throwable > circularityDetector ,
147- final @ NotNull Deque <SentryException > exceptions ) {
147+ final @ NotNull Deque <SentryException > exceptions ,
148+ final @ Nullable Integer parentIdOverride ) {
148149 Mechanism exceptionMechanism ;
149150 Thread thread ;
150151
151152 Throwable currentThrowable = throwable ;
152- int parentId = exceptionId .get ();
153+ int parentId = parentIdOverride == null ? exceptionId .get () : parentIdOverride ;
153154
154155 // Stack the exceptions to send them in the reverse order
155156 while (currentThrowable != null && circularityDetector .add (currentThrowable )) {
@@ -167,6 +168,21 @@ Deque<SentryException> extractExceptionQueueInternal(
167168 thread = Thread .currentThread ();
168169 }
169170
171+ if (currentThrowable instanceof SentryExceptionGroupException ) {
172+ exceptionMechanism .setExceptionGroup (true );
173+ }
174+
175+ Throwable [] suppressed = currentThrowable .getSuppressed ();
176+ if (suppressed != null && suppressed .length > 0 ) {
177+ extractExceptionQueueInternal (
178+ new SentryExceptionGroupException (),
179+ exceptionId ,
180+ circularityDetector ,
181+ exceptions ,
182+ null );
183+ parentId = exceptionId .get ();
184+ }
185+
170186 final boolean includeSentryFrames = Boolean .FALSE .equals (exceptionMechanism .isHandled ());
171187 final List <SentryStackFrame > frames =
172188 sentryStackTraceFactory .getStackFrames (
@@ -187,12 +203,10 @@ Deque<SentryException> extractExceptionQueueInternal(
187203 final int currentExceptionId = exceptionId .incrementAndGet ();
188204 exceptionMechanism .setExceptionId (currentExceptionId );
189205
190- Throwable [] suppressed = currentThrowable .getSuppressed ();
191206 if (suppressed != null && suppressed .length > 0 ) {
192- exceptionMechanism .setExceptionGroup (true );
193207 for (Throwable suppressedThrowable : suppressed ) {
194208 extractExceptionQueueInternal (
195- suppressedThrowable , exceptionId , circularityDetector , exceptions );
209+ suppressedThrowable , exceptionId , circularityDetector , exceptions , parentId );
196210 }
197211 }
198212 currentThrowable = currentThrowable .getCause ();
@@ -201,4 +215,8 @@ Deque<SentryException> extractExceptionQueueInternal(
201215
202216 return exceptions ;
203217 }
218+
219+ private static final class SentryExceptionGroupException extends RuntimeException {
220+ private static final long serialVersionUID = 6909700354645201267L ;
221+ }
204222}
0 commit comments