Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8251038

[macOS] Deadlock: Swing-embedded JavaFX, ContextMenu

XMLWordPrintable

    • x86_64
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      * macOS 10.14.6
      * AdoptOpenJDK 11.0.7+10
      * JavaFX 14.0.2.1

      A DESCRIPTION OF THE PROBLEM :
      A Swing application with embedded JavaFX (via JFXPanel) deadlocks when opening ContextMenu on macOS. I suspect this may also happen open windows in general (e.g., using JFX's FileChooser). I found deadlocks not to happen every time but it was frequent enough that anyone using my application would inevitably hit the deadlock and require Force Killing the application.

      In creating a minimal working example to demonstrate the bug, I found the surest way to reproduce was to open the application, switch to a different application and switch back, then try to open a ContextMenu a few times. This regularly caused the deadlock.

      Running with the Debugger in Netbeans, I paused the application at deadlock and found this stack trace for the JavaFX thread:

      The switching applications seems to be a key to getting the deadlock to happen. Testing with debugger in Netbeans, when the app freezes, I paused the app and saw this in the JavaFX Application Thread stack:

      "JavaFX Application Thread"
      at sun.lwawt.macosx.LWCToolkit.doAWTRunLoopImpl(LWCToolkit.java)
      at sun.lwawt.macosx.LWCToolkit.doAWTRunLoop(LWCToolkit.java:913)
      at sun.lwawt.macosx.LWCToolkit.invokeAndWait(LWCToolkit.java:694)
      at sun.lwawt.macosx.LWCToolkit.invokeAndWait(LWCToolkit.java:639)
      at sun.lwawt.macosx.CAccessibility.invokeAndWait(CAccessibility.java:94)
      at sun.lwawt.macosx.CAccessibility.getFocusOwner(CAccessibility.java:548)
      at com.sun.glass.ui.mac.MacWindow._setView(MacWindow.java)
      at com.sun.glass.ui.Window.setView(Window.java:416)
      at com.sun.javafx.tk.quantum.WindowStage.lambda$setScene$0(WindowStage.java:287)
      at com.sun.javafx.tk.quantum.WindowStage$$Lambda$359.792704517.get
      at com.sun.javafx.tk.quantum.QuantumToolkit.runWithRenderLock(QuantumToolkit.java:430)
      at com.sun.javafx.tk.quantum.WindowStage.setScene(WindowStage.java:286)
      at javafx.stage.Window$12.invalidated(Window.java:1085)
      at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110)
      at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:145)
      at javafx.stage.Window.setShowing(Window.java:1174)
      at javafx.stage.Window.show(Window.java:1189)
      at javafx.stage.PopupWindow.showImpl(PopupWindow.java:472)
      at javafx.stage.PopupWindow.show(PopupWindow.java:417)
      at javafx.scene.control.ContextMenu.doShow(ContextMenu.java:323)
      at javafx.scene.control.ContextMenu.show(ContextMenu.java:265)
      at com.kunstmusik.contextmenuhangingtest.HangingTest.lambda$main$0(HangingTest.java:29)
      at com.kunstmusik.contextmenuhangingtest.HangingTest$$Lambda$191.1699780362.handle
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
      at javafx.event.Event.fireEvent(Event.java:198)
      at javafx.scene.Node.fireEvent(Node.java:8885)
      at javafx.scene.control.Button.fire(Button.java:203)
      at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:206)
      at com.sun.javafx.scene.control.behavior.ButtonBehavior$$Lambda$247.642849157.handle
      at com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
      at com.sun.javafx.scene.control.inputmap.InputMap$$Lambda$242.1652994145.handle
      at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
      at javafx.event.Event.fireEvent(Event.java:198)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:3890)
      at javafx.scene.Scene.processMouseEvent(Scene.java:1885)
      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2618)
      at com.sun.javafx.tk.quantum.EmbeddedScene.lambda$mouseEvent$4(EmbeddedScene.java:287)
      at com.sun.javafx.tk.quantum.EmbeddedScene$$Lambda$322.1002466434.run
      at java.security.AccessController.doPrivileged(AccessController.java)
      at com.sun.javafx.tk.quantum.EmbeddedScene.lambda$mouseEvent$5(EmbeddedScene.java:280)
      at com.sun.javafx.tk.quantum.EmbeddedScene$$Lambda$321.1000105301.run
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
      at com.sun.javafx.application.PlatformImpl$$Lambda$163.1646337711.run
      at java.security.AccessController.doPrivileged(AccessController.java)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
      at com.sun.javafx.application.PlatformImpl$$Lambda$162.158199555.run
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)

      Note: In looking at the bug database, I found JDK-8214209 looked may be related.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Using the executable test case provided:

      * Launch application
      * Hit Button to show ContextMenu
      * Switch applications, then switch back
      * Repeatedly hit Button to show ContextMenu


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      App does not deadlock and require restart.
      ACTUAL -
      App deadlocks (beachball spinner shows) and is completely frozen. Requires Force Kill and restart of application.

      ---------- BEGIN SOURCE ----------
      Test project with maven pom available for easier testing at https://github.com/kunstmusik/ContextMenuHangingTest. Main test code is below:

      package com.kunstmusik.contextmenuhangingtest;

      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.geometry.Side;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ContextMenu;
      import javafx.scene.control.MenuItem;
      import static javafx.scene.layout.Region.USE_PREF_SIZE;
      import javax.swing.JFrame;

      public class HangingTest {
          
          public static void main(String args[]) {
               var frame = new JFrame("Hanging Test (macOS)");
               frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               
               final var jfxPanel = new JFXPanel();
               
               Platform.runLater(() -> {
                   
                   var ctxMenu = new ContextMenu(
                           new MenuItem("Test")
                   );
                   
                   final var btn = new Button("Show Context Menu");
                   btn.setOnAction(evt -> {
                       ctxMenu.show(btn, Side.TOP, USE_PREF_SIZE, USE_PREF_SIZE);
                   });
                   
                   var s = new Scene(btn);
                   jfxPanel.setScene(s);
               });
               
               frame.setContentPane(jfxPanel);
               
               frame.setSize(200, 200);
               
               frame.setVisible(true);
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None found.

      FREQUENCY : often


            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: