@@ -36,6 +36,7 @@ import org.utbot.framework.codegen.model.util.at
36
36
import org.utbot.framework.codegen.model.util.isAccessibleFrom
37
37
import org.utbot.framework.codegen.model.util.nullLiteral
38
38
import org.utbot.framework.codegen.model.util.resolve
39
+ import org.utbot.framework.plugin.api.BuiltinMethodId
39
40
import org.utbot.framework.plugin.api.ClassId
40
41
import org.utbot.framework.plugin.api.ConstructorId
41
42
import org.utbot.framework.plugin.api.ExecutableId
@@ -111,9 +112,8 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
111
112
112
113
// Builtin methods does not have jClass, so [methodId.method] will crash on it,
113
114
// so we need to collect required exceptions manually from source codes
114
- if (isUtil(methodId)) {
115
- utilMethodProvider
116
- .findExceptionTypesOf(methodId)
115
+ if (methodId is BuiltinMethodId ) {
116
+ findExceptionTypesOf(methodId)
117
117
.forEach { addExceptionIfNeeded(it) }
118
118
return
119
119
}
@@ -364,4 +364,35 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
364
364
365
365
return argumentsArrayVariable
366
366
}
367
+
368
+ // WARN: if you make changes in the following sets of exceptions,
369
+ // don't forget to change them in hardcoded [UtilMethods] as well
370
+ private fun findExceptionTypesOf (methodId : MethodId ): Set <ClassId > {
371
+ // TODO: at the moment we treat BuiltinMethodIds that are not util method ids
372
+ // as if they have no exceptions. This should be fixed by storing exception types in BuiltinMethodId
373
+ // or allowing us to access actual java.lang.Class for classes from mockito and other libraries
374
+ // (this could be possibly solved by using user project's class loaders in UtContext)
375
+ if (methodId !in utilMethodProvider.utilMethodIds) return emptySet()
376
+
377
+ with (utilMethodProvider) {
378
+ return when (methodId) {
379
+ getEnumConstantByNameMethodId -> setOf (java.lang.IllegalAccessException ::class .id)
380
+ getStaticFieldValueMethodId,
381
+ getFieldValueMethodId,
382
+ setStaticFieldMethodId,
383
+ setFieldMethodId -> setOf (java.lang.IllegalAccessException ::class .id, java.lang.NoSuchFieldException ::class .id)
384
+ createInstanceMethodId -> setOf (Exception ::class .id)
385
+ getUnsafeInstanceMethodId -> setOf (java.lang.ClassNotFoundException ::class .id, java.lang.NoSuchFieldException ::class .id, java.lang.IllegalAccessException ::class .id)
386
+ createArrayMethodId -> setOf (java.lang.ClassNotFoundException ::class .id)
387
+ deepEqualsMethodId,
388
+ arraysDeepEqualsMethodId,
389
+ iterablesDeepEqualsMethodId,
390
+ streamsDeepEqualsMethodId,
391
+ mapsDeepEqualsMethodId,
392
+ hasCustomEqualsMethodId,
393
+ getArrayLengthMethodId -> emptySet()
394
+ else -> error(" Unknown util method $this " )
395
+ }
396
+ }
397
+ }
367
398
}
0 commit comments