On Sat, 5 Sep 2026 11:48:23 GMT, Marius Hanl <[email protected]> wrote:

> This PR fixes a Warning I always get when JavaFX and Swing are both mixed 
> together in an application.
> The error: `XSetErrorHandler() called with a GDK error trap pushed. Don't do 
> that.`
> 
> I attached a small reproducer to the ticket. It shows the sequence that must 
> happen for this error to appear:
> 
> 1. JavaFX will call `gdk_error_trap_push` 
> 2. Swing will call `XSetErrorHandler`
> 3. GDK will detect that the error handler is different from the one we pushed
> 
> See also:
> - 
> https://gitlab.gnome.org/GNOME/gtk/-/blob/gtk-3-24/gdk/x11/gdkmain-x11.c#L313
> 
> ---
> 
> Checking the Swing code, we just call `XSetErrorHandler` and not 
> `gdk_error_trap_push`. See also:
> 
> - [Swing 
> XlibWrapper](https://github.com/openjdk/jdk/blob/master/src/java.desktop/unix/native/libawt_xawt/xawt/XlibWrapper.c#L1328)
> - [Swing 
> gtk3_interface](https://github.com/openjdk/jdk/blob/master/src/java.desktop/unix/native/libawt_xawt/awt/gtk3_interface.c#L679)
> 
> `gdk_error_trap_push` will call `XSetErrorHandler`, so we might as well do 
> that directly.
> I checked the code in `gdk_error_trap_push`, I do not see any problems with 
> this approach.
> 
> From what I understand, `gdk_error_trap_push` is meant to be short-lived, so 
> should be popped soon with `_gdk_error_handler_pop`. `XSetErrorHandler` makes 
> more sense as a 'long-lived' option, and it does the same for our usecase, 
> that is to not make the application exit on any `gdk_x_error`.
> 
> cc @tsayao, a review is appreciated.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

Ok I tested this and can confirm that the warning is printed without the fix 
and is no longer there with the fix. The code changes are also fairly 
straightforward.

-------------

Marked as reviewed by crschnick (Author).

PR Review: https://git.openjdk.org/jfx/pull/2296#pullrequestreview-5637429142

Reply via email to