garyttierney / intellij-ghidra

An IntelliJ IDEA plugin for working on Ghidra Extensions.
91 stars 19 forks source link

Cannot add facet if Ghidra is built with a newer JDK than what IntelliJ uses. #39

Open agatti opened 1 month ago

agatti commented 1 month ago

Describe the bug:

The plugin cannot work if Ghidra was compiled with a newer Java version than the one IntelliJ is running on.

Steps to reproduce:

  1. Have intellij-ghidra version 0.5.0 installed, straight from JetBrains' servers.
  2. Build Ghidra with Java 21 or higher.
  3. Load IntelliJ making sure the internal runtime is the one provided by JetBrains (hence using Java 17).
  4. Open a project, then add a Ghidra facet to a module.
  5. It won't be possible to commit changes in the dialog due to an internal exception.

The exception is as follows (kept just the interesting bits):

2024-07-23 16:33:40,661 [  51937] SEVERE - #c.i.i.p.PluginManager - ghidra/GhidraApplicationLayout has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0
java.lang.UnsupportedClassVersionError: ghidra/GhidraApplicationLayout has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
# <Internal class loader frames omitted>
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        at com.codingmates.ghidra.intellij.ide.facet.model.ProxyKt.createApplicationLayoutProxy(proxy.kt:46)
        at com.codingmates.ghidra.intellij.ide.facet.GhidraFacetSettings.resolve(GhidraFacetSettings.kt:19)
        at com.codingmates.ghidra.intellij.ide.facet.GhidraFacetConfigurationEditor.apply(GhidraFacetConfigurationEditor.kt:102)
        at com.intellij.openapi.options.UnnamedConfigurableGroup.apply(UnnamedConfigurableGroup.java:54)
        at com.intellij.facet.impl.ProjectFacetsConfigurator.applyEditors(ProjectFacetsConfigurator.java:253)
# <Internal IntelliJ frames omitted>

The exception is caught by IntelliJ itself and won't provide any feedback to the user (ie. you can click as many times as you want on either "Ok" or "Apply" but nothing will really happen).

Expected behavior:

Ideally there should be a better way to figure out Ghidra's directory layout, but if that's not possible then I guess some feedback to the user may help clarifying the situation. This is especially annoying if you have your package manager handle either Ghidra or IntelliJ (or both of them - look at Nix, Arch, etc.), or if you upgrade the default JVM at the wrong moment in time and IntelliJ starts misbehaving when you upgrade your Ghidra installation.

garyttierney commented 1 month ago

Hm, I think this could be solved by forking a new JVM (with whatever the project SDK is configured as) to run the directory layout code instead of trying to do it in-process, looking at now.

agatti commented 1 month ago

In the meantime, a temporary workaround is to force IntelliJ to use a runtime based on JDK 21 (see https://www.jetbrains.com/help/idea/switching-boot-jdk.html) - but a solution for this is needed until this plugin stops supporting IntelliJ versions that default to a JDK 17 runtime.

Keep in mind that Ghidra won't build on anything earlier than JDK 21 since mid-April, so starting from the next stable version of Ghidra this plugin won't work at all.