On Mon, 17 Aug 2026 10:38:12 GMT, Pabulaner IV <[email protected]> wrote:
>> # Problem description >> >> When You create a JavaFX native application with *jpackage* for macOS You >> will run into an issue when trying to handle URIs. When Your application >> isn’t running and You have it registered for handling certain types of URIs >> it won’t receive the first URI. >> >> ## Here is a simple example: >> >> If You have a JavaFX application that handles URIs for example of the form >> *openurifx://your-content* and You have it installed with *jpackage* for >> macOS and now You try to handle an URI by running the following command: >> >> ``` open openurifx://hello-world ``` >> >> The application will open, but it won’t receive the above URI. If You call >> the same command after the application is already running, everything will >> work fine and the application will receive the URI. >> >> # Problem cause >> >> The cause of the problem is that when You build a JavaFX application and >> want to handle URIs You will have to combine JavaFX and AWT as AWT provides >> the URI handling capabilities. So the startup process is as follows: >> >> 1. JavaFX is initialized >> 2. JavaFX forwards the URI event to AWT >> 3. AWT is initialized >> 4. AWT is ready to handle URI events from JavaFX >> >> The issue is that the URI event is delivered before AWT can handle it and >> therefore is simple dropped. That’s why later URIs will be received and are >> handled properly. >> >> # Fix >> >> The fix is that JavaFX will call Toolkit.getDefaultToolkit() once before >> forwarding an URI event. This way JavaFX can be sure that AWT is initialized >> and able to handle the event correctly. The needed change takes place inside >> the native code in GlassApplication.m on the MacOS side and is solved with >> reflection. >> >> # Tests >> >> To test the error and the fix You can clone this repository: >> https://github.com/pabulaner/openurifx and checkout the branch *first-url*. >> There You will find a README.md with further instructions. >> >> PR inside the JDK: https://github.com/openjdk/jdk/pull/31791 >> >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > Pabulaner IV has updated the pull request incrementally with one additional > commit since the last revision: > > 8198549: Desktop.setOpenURIHandler() only receives event if application is > already launched As mentioned above, I think the overall direction is good. Two comments: 1. The implementation as written won't work. See inline for details 2. speaking of which... This needs a test; it doesn't need to be an automated test (that might not even be possible) nor be wired up to the build, but we need some way to test it that isn't "run this application", "clone this GitHub project", or "run this `mvn` command." modules/javafx.graphics/src/main/native-glass/mac/GlassApplication.m line 225: > 223: } > 224: > 225: (*env)->CallVoidMethod(env, awt, method); This won't work as written. `Toolkit::getDefaultToolkit` is a static method (and doesn't return void). In addition to fixing this so it will work at all, you need to consider any possible threading issues that could lead to a deadlock, given that you are initializing AWT on the macOS AppKit thread. You will need to account for the possibility that another thread is initializing the AWT Toolkit concurrently with the `openURLs` message being delivered. `getDefaultToolkit` is a synchronized static method, so it holds a lock on `Toolkit.class`. If the toolkit initialization calls a method that needs to wait for the AppKit thread while _this_ method is trying to call `getDefaultToolkit()`, it would lead to deadlock. This might be easier to check for and handle in Java code. Consider doing a Java upcall to a MacApplication method and handle the AWT Toolkit initialization there. You'll still need to ensure that it doesn't deadlock, but implementing (and maintaining) that in Java might be easier. That method should return a `boolean` indicating success or failure. Set `awtInitialized` only upon success. ------------- PR Review: https://git.openjdk.org/jfx/pull/2203#pullrequestreview-5549244845 PR Review Comment: https://git.openjdk.org/jfx/pull/2203#discussion_r4295785601
