1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.basepom.mojo.propertyhelper;
18
19
20 import java.io.IOException;
21 import java.io.UncheckedIOException;
22 import java.lang.reflect.InvocationTargetException;
23
24 public final class Sneaky {
25
26 private Sneaky() {
27 }
28
29 public static RuntimeException throwAnyway(Throwable t) {
30
31 if (t instanceof Error) {
32 throw (Error) t;
33 } else if (t instanceof RuntimeException) {
34 throw (RuntimeException) t;
35 } else if (t instanceof IOException) {
36 throw new UncheckedIOException((IOException) t);
37 } else if (t instanceof InterruptedException) {
38 Thread.currentThread().interrupt();
39 } else if (t instanceof InvocationTargetException) {
40 throw throwAnyway(t.getCause());
41 }
42
43 throw throwEvadingChecks(t);
44 }
45
46 @SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
47 private static <E extends Throwable> E throwEvadingChecks(Throwable throwable) throws E {
48 throw (E) throwable;
49 }
50 }