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).

Suggestion

modules/javafx.graphics/src/main/native-glass/gtk/GlassApplication.cpp line 59:

> 57: static int glass_x_error_handler(Display*, XErrorEvent*)
> 58: {
> 59:     return 0;

Maybe print the output of [XGetErrorText() 
](https://tronche.com/gui/x/xlib/event-handling/protocol-errors/XGetErrorText.html)
 in DEBUG builds?

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

PR Review: https://git.openjdk.org/jfx/pull/2296#pullrequestreview-5713513546
PR Review Comment: https://git.openjdk.org/jfx/pull/2296#discussion_r4424511708

Reply via email to