Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About UnknownClass error #224

Open
cxf2006 opened this issue Mar 28, 2024 · 1 comment
Open

About UnknownClass error #224

cxf2006 opened this issue Mar 28, 2024 · 1 comment

Comments

@cxf2006
Copy link

cxf2006 commented Mar 28, 2024

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)))
}
}
}

@cxf2006
Copy link
Author

cxf2006 commented Jul 22, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant