@@ -127,15 +127,12 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
127
127
// Builtin methods does not have jClass, so [methodId.method] will crash on it,
128
128
// so we need to collect required exceptions manually from source codes
129
129
if (methodId is BuiltinMethodId ) {
130
- methodId.findExceptionTypes().forEach { addException (it) }
130
+ methodId.findExceptionTypes().forEach { addExceptionIfNeeded (it) }
131
131
return
132
132
}
133
- // If [InvocationTargetException] is thrown manually in test, we need
134
- // to add "throws Throwable" and other exceptions are not required so on.
133
+
135
134
if (methodId == getTargetException) {
136
- collectedExceptions.clear()
137
- addException(Throwable ::class .id)
138
- return
135
+ addExceptionIfNeeded(Throwable ::class .id)
139
136
}
140
137
141
138
val methodIsUnderTestAndThrowsExplicitly = methodId == currentExecutable
@@ -148,16 +145,18 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
148
145
return
149
146
}
150
147
151
- methodId.method.exceptionTypes.forEach { addException (it.id) }
148
+ methodId.method.exceptionTypes.forEach { addExceptionIfNeeded (it.id) }
152
149
}
153
150
154
151
private fun newConstructorCall (constructorId : ConstructorId ) {
155
152
importIfNeeded(constructorId.classId)
156
153
for (exception in constructorId.exceptions) {
157
- addException (exception)
154
+ addExceptionIfNeeded (exception)
158
155
}
159
156
}
160
157
158
+ // WARN: if you make changes in the following sets of exceptions,
159
+ // don't forget to change them in hardcoded [UtilMethods] as well
161
160
private fun BuiltinMethodId.findExceptionTypes (): Set <ClassId > {
162
161
if (! this .isUtil) return emptySet()
163
162
@@ -167,9 +166,9 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
167
166
getStaticFieldValueMethodId,
168
167
getFieldValueMethodId,
169
168
setStaticFieldMethodId,
170
- setFieldMethodId,
171
- createInstanceMethodId,
172
- getUnsafeInstanceMethodId -> setOf (Exception ::class .id)
169
+ setFieldMethodId -> setOf ( IllegalAccessException :: class .id, NoSuchFieldException :: class .id)
170
+ createInstanceMethodId -> setOf ( Exception :: class .id)
171
+ getUnsafeInstanceMethodId -> setOf (ClassNotFoundException :: class .id, NoSuchFieldException :: class .id, IllegalAccessException ::class .id)
173
172
createArrayMethodId -> setOf (ClassNotFoundException ::class .id)
174
173
deepEqualsMethodId,
175
174
arraysDeepEqualsMethodId,
0 commit comments