Skip to content
This repository has been archived by the owner on Sep 2, 2020. It is now read-only.

The stacktrace of a wrapped AggregateException excludes the inner exceptions #105

Open
grantland opened this issue Dec 4, 2015 · 0 comments
Labels

Comments

@grantland
Copy link
Member

Printing the stacktrace of a wrapped AggregateException does not include the inner exceptions:

Exception e1 = new RuntimeException("Failure 1");
Exception e2 = new RuntimeException("Failure 2");

Exception aggregate = new AggregateException(Arrays.asList(e1, e2));

aggregate.printStackTrace();
// bolts.AggregateException: There were multiple errors.
//     at bolts.TaskTest.testThing(TaskTest.java:1160)
//     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
//     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
//     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
//     at java.lang.reflect.Method.invoke(Method.java:606)
//     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
//     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
//     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
//     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
//     at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
//     at org.junit.rules.RunRules.evaluate(RunRules.java:20)
//     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
//     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
//     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
//     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
//     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
//     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
//     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
//     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
//     at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
//     at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
//     at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
//     at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
//     at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
//     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
//     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
//     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
//     at java.lang.reflect.Method.invoke(Method.java:606)
//     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
// Caused by: java.lang.RuntimeException: Failure 1
//     at bolts.TaskTest.testThing(TaskTest.java:1157)
//     ... 28 more
// 
//   Inner throwable #0: java.lang.RuntimeException: Failure 1
//     at bolts.TaskTest.testThing(TaskTest.java:1157)
//     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
//     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
//     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
//     at java.lang.reflect.Method.invoke(Method.java:606)
//     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
//     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
//     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
//     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
//     at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
//     at org.junit.rules.RunRules.evaluate(RunRules.java:20)
//     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
//     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
//     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
//     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
//     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
//     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
//     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
//     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
//     at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
//     at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
//     at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
//     at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
//     at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
//     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
//     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
//     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
//     at java.lang.reflect.Method.invoke(Method.java:606)
//     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
// 
// 
//   Inner throwable #1: java.lang.RuntimeException: Failure 2
//     at bolts.TaskTest.testThing(TaskTest.java:1158)
//     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
//     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
//     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
//     at java.lang.reflect.Method.invoke(Method.java:606)
//     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
//     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
//     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
//     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
//     at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
//     at org.junit.rules.RunRules.evaluate(RunRules.java:20)
//     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
//     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
//     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
//     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
//     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
//     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
//     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
//     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
//     at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
//     at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
//     at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
//     at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
//     at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
//     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
//     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
//     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
//     at java.lang.reflect.Method.invoke(Method.java:606)
//     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

new Exception(aggregate).printStackTrace();
// java.lang.Exception: bolts.AggregateException: There were multiple errors.
//     at bolts.TaskTest.testThing(TaskTest.java:1164)
//     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
//     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
//     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
//     at java.lang.reflect.Method.invoke(Method.java:606)
//     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
//     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
//     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
//     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
//     at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
//     at org.junit.rules.RunRules.evaluate(RunRules.java:20)
//     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
//     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
//     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
//     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
//     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
//     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
//     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
//     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
//     at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
//     at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
//     at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
//     at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
//     at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
//     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
//     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
//     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
//     at java.lang.reflect.Method.invoke(Method.java:606)
//     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
// Caused by: bolts.AggregateException: There were multiple errors.
//     at bolts.TaskTest.testThing(TaskTest.java:1160)
//     ... 28 more
// Caused by: java.lang.RuntimeException: Failure 1
//     at bolts.TaskTest.testThing(TaskTest.java:1157)
//     ... 28 more

It seems like the proper way to handle this would be to utilize Throwable#addSuppressed(throwable) instead, but this requires android-19 :(

@grantland grantland added the bug label Dec 4, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant