Skip to content

About UnknownClass error #224

Description

@cxf2006

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:
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:
false
virtual org.jacodb.impl.features.classpaths.JcUnknownClass@38bd1452#INSTANCE
org.jacodb.analysis.engine.ZEROFact

A judgment has been added to the call point to temporarily solve the problem.
org.jacodb.analysis.paths.Util.kt
if (this is JcFieldRef) { // line num 44
val instance = instance // enables smart cast

return if (instance == null) {
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)))
}
}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions