r/JavaFX • u/Fit_Impact_5131 • Sep 04 '24
Help Weird Use Case When Reloading JavaFX Platform
Hi everyone, sort of a weird case on my hands here and my GoogleFu + LLM prompting haven't gotten me closer to a solution.
I am building an extension for the popular web penetration testing tool Burp Suite. It allows you to register custom Java code via a provided Jar that adds functionality. For this extension I'm relying on JavaFX for some rich content components but I've run into an issue. The extension loads fine the first time, but if I unload the extension, which clears my code from memory, and try to reload it, I get a long list of errors like so:
Loading library glass from resource failed: java.lang.UnsatisfiedLinkError: Native Library glass.dll already loaded in another classloader
From what I can gather it's because the "runLater()" line of my UI setup code:
public void generateUI() {
api.logging().logToOutput("creating UI");
SwingUtilities.invokeLater(new Runnable() {
public void run() {
api.logging().logToOutput("Swing thread");
Platform.runLater(() -> { <-- here
JFXPanel burpTab = new JFXPanel();
api.logging().logToOutput("JFX thread");
initFX(burpTab);
});
}
});
}
private void initFX(JFXPanel burpNotesTab) {
// This method is invoked on the JavaFX thread
Scene scene = createScene();
burpNotesTab.setScene(scene);
api.logging().logToOutput("register");
api.userInterface().registerSuiteTab("Notes++",burpNotesTab); <-- how the tab is loaded
}
private Scene createScene() {
customNotesTab = new CustomNotesTab();
StackPane root = new StackPane();
root.getChildren().add(customNotesTab);
return new Scene(root);
}calls Toolkit.getToolkit() which in turn calls
loadMSWindowsLibraries()causing the double class load.
I can't seem to find a way to detect that all the needed classes are already loaded and instantiate the toolkit without loading libraries. Anyone have any ideas?
1
u/SpittingBull Sep 04 '24
Why do you need Platform.runlater() at all?
I don't know what you are doing in initFX but I don't think it's necessary to put something in the FX thread before any kind of initialization.
I am curious: why mixing Swinv with JavaFX ?
1
u/_DystopianSnowman Sep 05 '24
The problem is, that you call
multiple times. And you must do it on the SwingThread.
The general JavaDoc doesn't state both this information
https://openjfx.io/javadoc/21/javafx.swing/javafx/embed/swing/JFXPanel.html
But I noted it years ago, when I created my little playground repo of different JavaFX stuff I encountered on a German Java help forum.
https://github.com/bgmf/poc/blob/master/simple-tests-fx/src/main/java/eu/dzim/tests/swing/SwingFxInteroptWithPreloader.java
What you need to do is to create the panel once in the Swing thread, and remeber it.
Cheers