mabe02 / lanterna

Java library for creating text-based GUIs
GNU Lesser General Public License v3.0
2.26k stars 242 forks source link

GraalVM: ClassNotFoundException: com.googlecode.lanterna.gui2.Button$DefaultButtonRenderer #521

Open jgautheron opened 3 years ago

jgautheron commented 3 years ago

When compiling natively my project with GraalVM 20.2.0 CE, I get the following error:

java.lang.RuntimeException: java.lang.ClassNotFoundException: com.googlecode.lanterna.gui2.Button$DefaultButtonRenderer
    at com.googlecode.lanterna.graphics.AbstractTheme.instanceByClassName(AbstractTheme.java:142)
    at com.googlecode.lanterna.graphics.AbstractTheme$DefinitionImpl.getRenderer(AbstractTheme.java:301)
    at com.googlecode.lanterna.gui2.AbstractComponent.getRenderer(AbstractComponent.java:137)
    at com.googlecode.lanterna.gui2.AbstractInteractableComponent.getRenderer(AbstractInteractableComponent.java:109)

I'm trying to compile this example: https://github.com/mabe02/lanterna/blob/master/docs/examples/gui/hello_world.md with a small change (replaced createTerminal by createHeadlessTerminal). If I remove the button it works fine.

Version: 3.1.0-beta2

avl42 commented 3 years ago

Renderer classes in Lanterna are usually not "hardreferenced", but dynamically loaded. This is, because it is in principle also allowed to add custom renderers to standard widgets.

Either you have to tell GraalVM to also include the *Renderer classes, or Lanterna would need to hard-ref the default-renderers while still keeping a way to override them.

I'm not sure how often "replacing renderers" is really used, because my (bubble-)memory seems to recall some cases where renderers needed access to non-public state of widgets, making it pretty hard to replace them with custom classes in other packages in practice...

mabe02 commented 3 years ago

We could add a synthetic hard-reference to the renderers that comes with lanterna. I'm assuming it's enough to just have them imported and referenced, even if the code does nothing?

mabe02 commented 3 years ago

@jgautheron see if you can compile release/3.0 from source and see if the commit above fixes the issue?

jgautheron commented 3 years ago

@mabe02 Thanks for that! I'm using gradle and it won't let me reference a maven source project. Could you maybe create a patch version?

mabe02 commented 3 years ago

What if you clone it locally and rebuild it? Surely gradle will let you use local repo maven artifacts.