Open cxf2006 opened 5 months ago
When analyzing a project, sometimes it is impossible to obtain all dependent packages of the analyzed code, so the UnknownClass feature is used. However, the error described above will occur. Jacodb requires that all dependent jar packages of the analyzed code must be loaded into Jacodb? Can anyone help answer this question?
V1.4.5
Run the Unused analysis that comes with the project
{
"analyses": [
{
"name": "Unused",
"unitResolver": "method"
}
]
}
set UnknownClass feature
database.asyncClasspath(classpath, List.of(UnknownClasses.INSTANCE, UnknownClassMethodsAndFields.INSTANCE)).get()
The following error occurs:
Expected static field
java.lang.IllegalArgumentException: Expected static field
at org.jacodb.analysis.paths.AccessPath$Companion.fromStaticField(AccessPath.kt:36)
at org.jacodb.analysis.paths.UtilKt.toPathOrNull(Util.kt:49)
at org.jacodb.analysis.library.analyzers.UnusedVariableAnalyzer.isUsedAt(UnusedVariableAnalyzer.kt:66)
at org.jacodb.analysis.library.analyzers.UnusedVariableAnalyzer.isUsedAt(UnusedVariableAnalyzer.kt:84)
at org.jacodb.analysis.library.analyzers.UnusedVariableAnalyzer.handleIfdsResult(UnusedVariableAnalyzer.kt:104)
at org.jacodb.analysis.engine.BaseIfdsUnitRunner$run$2$1.invokeSuspend(BaseIfdsUnitRunnerFactory.kt:252)
at org.jacodb.analysis.engine.BaseIfdsUnitRunner$run$2$1.invoke(BaseIfdsUnitRunnerFactory.kt)
at org.jacodb.analysis.engine.BaseIfdsUnitRunner$run$2$1.invoke(BaseIfdsUnitRunnerFactory.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:169)
at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
at org.jacodb.analysis.engine.BaseIfdsUnitRunner$run$2.invokeSuspend(BaseIfdsUnitRunnerFactory.kt:251)
at org.jacodb.analysis.engine.BaseIfdsUnitRunner$run$2.invoke(BaseIfdsUnitRunnerFactory.kt)
at org.jacodb.analysis.engine.BaseIfdsUnitRunner$run$2.invoke(BaseIfdsUnitRunnerFactory.kt)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
at org.jacodb.analysis.engine.BaseIfdsUnitRunner.run(BaseIfdsUnitRunnerFactory.kt:235)
at org.jacodb.analysis.engine.AbstractIfdsUnitRunner$launchIn$1.invokeSuspend(IfdsUnitRunnerFactory.kt:67)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Added debugging information:
}
virtual org.jacodb.impl.features.classpaths.JcUnknownClass@38bd1452#INSTANCE
org.jacodb.analysis.engine.ZEROFact`
org.jacodb.analysis.paths.AccessPath.kt
fun fromStaticField(field: JcField): AccessPath {
if (!field.isStatic) {
System.out.println(field.isStatic)
System.out.println(field)
System.out.println(field.type)
throw IllegalArgumentException("Expected static field")
}
`
return AccessPath(null, listOf(FieldAccessor(field)))Print the following information:
falseA judgment has been added to the call point to temporarily solve the problem.
if (field.field.isStatic) { // Judgment added here
AccessPath.fromStaticField(field.field)
} else {
return null
}
} else {
instance.toPathOrNull()?.let {
AccessPath.fromOther(it, listOf(FieldAccessor(field.field)))
}
}
}`
org.jacodb.analysis.paths.Util.kt
if (this is JcFieldRef) { // line num 44
val instance = instance // enables smart cast
`
return if (instance == null) {