1
1
/*
2
- * Copyright (c) 2017, 2021 Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
3
3
*/
4
4
/*
5
5
* Licensed to the Apache Software Foundation (ASF) under one or more
20
20
21
21
package com .sun .org .apache .bcel .internal ;
22
22
23
+ import jdk .xml .internal .Utils ;
24
+
23
25
/**
24
26
* Exception constants.
27
+ *
25
28
* @since 6.0 (intended to replace the InstructionConstant interface)
26
- * @LastModified: May 2021
29
+ * @LastModified: Feb 2023
27
30
*/
28
31
public final class ExceptionConst {
29
32
33
+ /**
34
+ * Enum corresponding to the various Exception Class arrays, used by
35
+ * {@link ExceptionConst#createExceptions(EXCS, Class...)}
36
+ */
37
+ public enum EXCS {
38
+ EXCS_CLASS_AND_INTERFACE_RESOLUTION , EXCS_FIELD_AND_METHOD_RESOLUTION , EXCS_INTERFACE_METHOD_RESOLUTION , EXCS_STRING_RESOLUTION , EXCS_ARRAY_EXCEPTION ,
39
+ }
40
+
30
41
/**
31
42
* The mother of all exceptions
32
43
*/
@@ -64,61 +75,41 @@ public final class ExceptionConst {
64
75
* Run-Time Exceptions
65
76
*/
66
77
public static final Class <NullPointerException > NULL_POINTER_EXCEPTION = NullPointerException .class ;
67
- public static final Class <ArrayIndexOutOfBoundsException > ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION
68
- = ArrayIndexOutOfBoundsException .class ;
78
+ public static final Class <ArrayIndexOutOfBoundsException > ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION = ArrayIndexOutOfBoundsException .class ;
69
79
public static final Class <ArithmeticException > ARITHMETIC_EXCEPTION = ArithmeticException .class ;
70
80
public static final Class <NegativeArraySizeException > NEGATIVE_ARRAY_SIZE_EXCEPTION = NegativeArraySizeException .class ;
71
81
public static final Class <ClassCastException > CLASS_CAST_EXCEPTION = ClassCastException .class ;
82
+
72
83
public static final Class <IllegalMonitorStateException > ILLEGAL_MONITOR_STATE = IllegalMonitorStateException .class ;
84
+ /**
85
+ * Pre-defined exception arrays according to chapters 5.1-5.4 of the Java Virtual Machine Specification
86
+ */
87
+ private static final Class <?>[] EXCS_CLASS_AND_INTERFACE_RESOLUTION = {NO_CLASS_DEF_FOUND_ERROR , CLASS_FORMAT_ERROR , VERIFY_ERROR , ABSTRACT_METHOD_ERROR ,
88
+ EXCEPTION_IN_INITIALIZER_ERROR , ILLEGAL_ACCESS_ERROR }; // Chapter 5.1
89
+
90
+ private static final Class <?>[] EXCS_FIELD_AND_METHOD_RESOLUTION = {NO_SUCH_FIELD_ERROR , ILLEGAL_ACCESS_ERROR , NO_SUCH_METHOD_ERROR }; // Chapter 5.2
73
91
74
92
/**
75
- * Pre-defined exception arrays according to chapters 5.1-5.4 of the Java Virtual
76
- * Machine Specification
93
+ * Empty array.
77
94
*/
78
- private static final Class <?>[] EXCS_CLASS_AND_INTERFACE_RESOLUTION = {
79
- NO_CLASS_DEF_FOUND_ERROR , CLASS_FORMAT_ERROR , VERIFY_ERROR , ABSTRACT_METHOD_ERROR ,
80
- EXCEPTION_IN_INITIALIZER_ERROR , ILLEGAL_ACCESS_ERROR
81
- }; // Chapter 5.1
82
- private static final Class <?>[] EXCS_FIELD_AND_METHOD_RESOLUTION = {
83
- NO_SUCH_FIELD_ERROR , ILLEGAL_ACCESS_ERROR , NO_SUCH_METHOD_ERROR
84
- }; // Chapter 5.2
85
95
private static final Class <?>[] EXCS_INTERFACE_METHOD_RESOLUTION = new Class <?>[0 ]; // Chapter 5.3 (as below)
86
- private static final Class <?>[] EXCS_STRING_RESOLUTION = new Class <?>[0 ];
87
- // Chapter 5.4 (no errors but the ones that _always_ could happen! How stupid.)
88
- private static final Class <?>[] EXCS_ARRAY_EXCEPTION = {
89
- NULL_POINTER_EXCEPTION , ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION
90
- };
91
96
92
97
/**
93
- * Enum corresponding to the various Exception Class arrays,
94
- * used by {@link ExceptionConst#createExceptions(EXCS, Class...)}
98
+ * Empty array.
95
99
*/
96
- public enum EXCS {
97
- EXCS_CLASS_AND_INTERFACE_RESOLUTION ,
98
- EXCS_FIELD_AND_METHOD_RESOLUTION ,
99
- EXCS_INTERFACE_METHOD_RESOLUTION ,
100
- EXCS_STRING_RESOLUTION ,
101
- EXCS_ARRAY_EXCEPTION ,
102
- }
100
+ private static final Class <?>[] EXCS_STRING_RESOLUTION = new Class <?>[0 ];
103
101
104
- // helper method to merge exception class arrays
105
- private static Class <?>[] mergeExceptions (final Class <?>[] input , final Class <?> ... extraClasses ) {
106
- final int extraLen = extraClasses == null ? 0 : extraClasses .length ;
107
- final Class <?>[] excs = new Class <?>[input .length + extraLen ];
108
- System .arraycopy (input , 0 , excs , 0 , input .length );
109
- if (extraLen > 0 ) {
110
- System .arraycopy (extraClasses , 0 , excs , input .length , extraLen );
111
- }
112
- return excs ;
113
- }
102
+ // Chapter 5.4 (no errors but the ones that _always_ could happen! How stupid.)
103
+ private static final Class <?>[] EXCS_ARRAY_EXCEPTION = {NULL_POINTER_EXCEPTION , ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION };
114
104
115
105
/**
116
106
* Creates a copy of the specified Exception Class array combined with any additional Exception classes.
107
+ *
117
108
* @param type the basic array type
118
109
* @param extraClasses additional classes, if any
119
110
* @return the merged array
120
111
*/
121
- public static Class <?>[] createExceptions (final EXCS type , final Class <?> ... extraClasses ) {
112
+ public static Class <?>[] createExceptions (final EXCS type , final Class <?>... extraClasses ) {
122
113
switch (type ) {
123
114
case EXCS_CLASS_AND_INTERFACE_RESOLUTION :
124
115
return mergeExceptions (EXCS_CLASS_AND_INTERFACE_RESOLUTION , extraClasses );
@@ -135,5 +126,8 @@ public static Class<?>[] createExceptions(final EXCS type, final Class<?> ... ex
135
126
}
136
127
}
137
128
138
-
129
+ // helper method to merge exception class arrays
130
+ private static Class <?>[] mergeExceptions (final Class <?>[] input , final Class <?>... extraClasses ) {
131
+ return Utils .arraysAppend (input , extraClasses );
132
+ }
139
133
}
0 commit comments