1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel;
18
19 import org.apache.commons.lang3.ArrayUtils;
20
21
22
23
24
25
26 public final class ExceptionConst {
27
28
29
30
31
32 public enum EXCS {
33 EXCS_CLASS_AND_INTERFACE_RESOLUTION, EXCS_FIELD_AND_METHOD_RESOLUTION, EXCS_INTERFACE_METHOD_RESOLUTION, EXCS_STRING_RESOLUTION, EXCS_ARRAY_EXCEPTION,
34 }
35
36
37
38
39 public static final Class<Throwable> THROWABLE = Throwable.class;
40
41
42
43
44 public static final Class<RuntimeException> RUNTIME_EXCEPTION = RuntimeException.class;
45
46
47
48
49 public static final Class<LinkageError> LINKING_EXCEPTION = LinkageError.class;
50
51
52
53 public static final Class<ClassCircularityError> CLASS_CIRCULARITY_ERROR = ClassCircularityError.class;
54 public static final Class<ClassFormatError> CLASS_FORMAT_ERROR = ClassFormatError.class;
55 public static final Class<ExceptionInInitializerError> EXCEPTION_IN_INITIALIZER_ERROR = ExceptionInInitializerError.class;
56 public static final Class<IncompatibleClassChangeError> INCOMPATIBLE_CLASS_CHANGE_ERROR = IncompatibleClassChangeError.class;
57 public static final Class<AbstractMethodError> ABSTRACT_METHOD_ERROR = AbstractMethodError.class;
58 public static final Class<IllegalAccessError> ILLEGAL_ACCESS_ERROR = IllegalAccessError.class;
59 public static final Class<InstantiationError> INSTANTIATION_ERROR = InstantiationError.class;
60 public static final Class<NoSuchFieldError> NO_SUCH_FIELD_ERROR = NoSuchFieldError.class;
61 public static final Class<NoSuchMethodError> NO_SUCH_METHOD_ERROR = NoSuchMethodError.class;
62 public static final Class<NoClassDefFoundError> NO_CLASS_DEF_FOUND_ERROR = NoClassDefFoundError.class;
63 public static final Class<UnsatisfiedLinkError> UNSATISFIED_LINK_ERROR = UnsatisfiedLinkError.class;
64
65 public static final Class<VerifyError> VERIFY_ERROR = VerifyError.class;
66
67
68
69
70
71 public static final Class<NullPointerException> NULL_POINTER_EXCEPTION = NullPointerException.class;
72 public static final Class<ArrayIndexOutOfBoundsException> ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION = ArrayIndexOutOfBoundsException.class;
73 public static final Class<ArithmeticException> ARITHMETIC_EXCEPTION = ArithmeticException.class;
74 public static final Class<NegativeArraySizeException> NEGATIVE_ARRAY_SIZE_EXCEPTION = NegativeArraySizeException.class;
75 public static final Class<ClassCastException> CLASS_CAST_EXCEPTION = ClassCastException.class;
76
77 public static final Class<IllegalMonitorStateException> ILLEGAL_MONITOR_STATE = IllegalMonitorStateException.class;
78
79
80
81 private static final Class<?>[] EXCS_CLASS_AND_INTERFACE_RESOLUTION = {NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR,
82 EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR};
83
84 private static final Class<?>[] EXCS_FIELD_AND_METHOD_RESOLUTION = {NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR};
85
86
87
88
89 private static final Class<?>[] EXCS_INTERFACE_METHOD_RESOLUTION = new Class[0];
90
91
92
93
94 private static final Class<?>[] EXCS_STRING_RESOLUTION = new Class[0];
95
96
97 private static final Class<?>[] EXCS_ARRAY_EXCEPTION = {NULL_POINTER_EXCEPTION, ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION};
98
99
100
101
102
103
104
105
106 public static Class<?>[] createExceptions(final EXCS type, final Class<?>... extraClasses) {
107 switch (type) {
108 case EXCS_CLASS_AND_INTERFACE_RESOLUTION:
109 return mergeExceptions(EXCS_CLASS_AND_INTERFACE_RESOLUTION, extraClasses);
110 case EXCS_ARRAY_EXCEPTION:
111 return mergeExceptions(EXCS_ARRAY_EXCEPTION, extraClasses);
112 case EXCS_FIELD_AND_METHOD_RESOLUTION:
113 return mergeExceptions(EXCS_FIELD_AND_METHOD_RESOLUTION, extraClasses);
114 case EXCS_INTERFACE_METHOD_RESOLUTION:
115 return mergeExceptions(EXCS_INTERFACE_METHOD_RESOLUTION, extraClasses);
116 case EXCS_STRING_RESOLUTION:
117 return mergeExceptions(EXCS_STRING_RESOLUTION, extraClasses);
118 default:
119 throw new AssertionError("Cannot happen; unexpected enum value: " + type);
120 }
121 }
122
123
124 private static Class<?>[] mergeExceptions(final Class<?>[] input, final Class<?>... extraClasses) {
125 return ArrayUtils.addAll(input, extraClasses);
126 }
127
128 }