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

cpg-console error about kotlin version #2029

Open
vaioco opened this issue Feb 6, 2025 · 5 comments
Open

cpg-console error about kotlin version #2029

vaioco opened this issue Feb 6, 2025 · 5 comments

Comments

@vaioco
Copy link

vaioco commented Feb 6, 2025

Runtime errors due to incompatible kotlin compiler. It seems a regression of #1272 or that fix was incomplete.

I am on latest commit 0d28981 running openjdk 17 on ubuntu machine.

 # java --version
openjdk 17.0.14 2025-01-21
OpenJDK Runtime Environment Homebrew (build 17.0.14+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.14+0, mixed mode, sharing)

After building with I with./gradlew clean :cpg-console:installDist I get the following error at runtime.

ki-shell 0.5.3-SNAPSHOT/2.1.0
[0] :run
ERROR Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.1.0, but the compiler version 1.9.0 can read versions up to 2.0.0.
The class is loaded from cpg-console/lib/kotlin-stdlib-2.1.0.jar!/kotlin/Unit.class (Line_3.kts:1:20)
ERROR Unresolved reference: result (Line_3.kts:1:24)
ERROR Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.1.0, but the compiler version 1.9.0 can read versions up to 2.0.0.
The class is loaded from cpg-console/lib/kotlin-stdlib-2.1.0.jar!/kotlin/Unit.class (Line_4.kts:1:20)
ERROR Unresolved reference: result (Line_4.kts:1:24)
@oxisto
Copy link
Member

oxisto commented Feb 6, 2025

Unfortunately the console is hard to maintain, since ki-shell is semi unmaintained by JetBrains and is still running Kotlin 1.9. In the long run we want to explore other options and it looks like it broke again without us noticing :( Maybe this will be the final nail on the coffin for the console.

@vaioco
Copy link
Author

vaioco commented Feb 6, 2025

I tried compiling cpg with kotlin 1.9 but it did not work.
Is there any available workaround for overcoming this issue?

I think the cpg-console is quite an important component for the users trying to explore this tool.

thanks!

@oxisto
Copy link
Member

oxisto commented Feb 6, 2025

Ok it seems you can just ignore this error. The analysis still works (although with more warnings).

:tr cpg-neo4j/src/integrationTest/resources/test.py
.....
[19] result
res19: de.fraunhofer.aisec.cpg.TranslationResult = TranslationResult{
  location=<null>
}
[20] result.functions
res20: List<de.fraunhofer.aisec.cpg.graph.declarations.FunctionDeclaration> = [FunctionDeclaration{
  name=test.main
  location=test.py(3:1-4:25)
  parameters=de.fraunhofer.aisec.cpg.graph.edges.collections.UnwrappedEdgeList@472a4ac9
}, FunctionDeclaration{
  name=print
  location=<null>
  parameters=de.fraunhofer.aisec.cpg.graph.edges.collections.UnwrappedEdgeList@7b17c7d6
}]

@vaioco
Copy link
Author

vaioco commented Feb 6, 2025

Ok it seems you can just ignore this error. The analysis still works (although with more warnings).

:tr cpg-neo4j/src/integrationTest/resources/test.py
.....
[19] result
res19: de.fraunhofer.aisec.cpg.TranslationResult = TranslationResult{
  location=<null>
}
[20] result.functions
res20: List<de.fraunhofer.aisec.cpg.graph.declarations.FunctionDeclaration> = [FunctionDeclaration{
  name=test.main
  location=test.py(3:1-4:25)
  parameters=de.fraunhofer.aisec.cpg.graph.edges.collections.UnwrappedEdgeList@472a4ac9
}, FunctionDeclaration{
  name=print
  location=<null>
  parameters=de.fraunhofer.aisec.cpg.graph.edges.collections.UnwrappedEdgeList@7b17c7d6
}]

I am trying to follow the tutorial https://github.com/Fraunhofer-AISEC/cpg/blob/main/tutorial.md but it seems updated as some commands are not available anymore.
This below is what I get with latest release:

type :h for help
[0] :tr ./cpg-language-cxx/src/test/resources/c/
[....]
[24] :run
ERROR Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.1.0, but the compiler version 1.9.0 can read versions up to 2.0.0.
The class is loaded from /Users/valerio/tools/sast/joern_suite/cpg/cpg-console/build/install/cpg-console/lib/kotlin-stdlib-2.1.0.jar!/kotlin/Unit.class (Line_27.kts:1:20)
ERROR Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.1.0, but the compiler version 1.9.0 can read versions up to 2.0.0.
The class is loaded from /Users/valerio/tools/sast/joern_suite/cpg/cpg-console/build/install/cpg-console/lib/kotlin-stdlib-2.1.0.jar!/kotlin/Unit.class (Line_28.kts:1:20)
[...]
[32] result.all()
ERROR Unresolved reference: all (Line_33.kts:1:8)

is the :run output as intended? the analysis is actually executed?
I tried adding in the C test code an artificial out-of-bound bug and it was not detected.

thanks!

@oxisto
Copy link
Member

oxisto commented Feb 7, 2025

Ok it seems you can just ignore this error. The analysis still works (although with more warnings).

:tr cpg-neo4j/src/integrationTest/resources/test.py
.....
[19] result
res19: de.fraunhofer.aisec.cpg.TranslationResult = TranslationResult{
  location=<null>
}
[20] result.functions
res20: List<de.fraunhofer.aisec.cpg.graph.declarations.FunctionDeclaration> = [FunctionDeclaration{
  name=test.main
  location=test.py(3:1-4:25)
  parameters=de.fraunhofer.aisec.cpg.graph.edges.collections.UnwrappedEdgeList@472a4ac9
}, FunctionDeclaration{
  name=print
  location=<null>
  parameters=de.fraunhofer.aisec.cpg.graph.edges.collections.UnwrappedEdgeList@7b17c7d6
}]

I am trying to follow the tutorial https://github.com/Fraunhofer-AISEC/cpg/blob/main/tutorial.md but it seems updated as some commands are not available anymore. This below is what I get with latest release:

type :h for help
[0] :tr ./cpg-language-cxx/src/test/resources/c/
[....]
[24] :run
ERROR Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.1.0, but the compiler version 1.9.0 can read versions up to 2.0.0.
The class is loaded from /Users/valerio/tools/sast/joern_suite/cpg/cpg-console/build/install/cpg-console/lib/kotlin-stdlib-2.1.0.jar!/kotlin/Unit.class (Line_27.kts:1:20)
ERROR Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.1.0, but the compiler version 1.9.0 can read versions up to 2.0.0.
The class is loaded from /Users/valerio/tools/sast/joern_suite/cpg/cpg-console/build/install/cpg-console/lib/kotlin-stdlib-2.1.0.jar!/kotlin/Unit.class (Line_28.kts:1:20)
[...]
[32] result.all()
ERROR Unresolved reference: all (Line_33.kts:1:8)

is the :run output as intended? the analysis is actually executed? I tried adding in the C test code an artificial out-of-bound bug and it was not detected.

thanks!

The commands are still valid, but it seems like that even though we explicitly tried to stay in Kotlin 2.0.X, somehow some kotlin dependencies updated themselves to Kotlin 2.1.0 and because the console uses ki-shell and ki-shell does not work with 2.10 (see Kotlin/kotlin-interactive-shell#131), we are stuck here :(

In the long run the only viable option would be to replace the shell altogether, unfortunately there is not really something available in terms of a good Kotlin REPL that we can just use as a dependency :(

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

2 participants