JDK-8088859 : [Mac] Cannot exit FX application while file chooser is opened
  • Type: Bug
  • Component: javafx
  • Sub-Component: window-toolkit
  • Affected Version: 8,9
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2014-03-04
  • Updated: 2019-03-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
If you invoke Platform.exit while a FileChooser is opened, the application does not quit properly :
- application window is dismissed but FileChooser is still there
- if you click on the cancel button of the file chooser, the file chooser window is dismissed BUT the process is still alive and an exception is thrown (see below). At this time, you have to Force quit the app.

Simple Test.java attached to reproduce.

Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: This operation is permitted on the event thread only; currentThread = JavaFX Application Thread
	at com.sun.glass.ui.Application.checkEventThread(Application.java:427)
	at com.sun.glass.ui.EventLoop.leave(EventLoop.java:159)
	at com.sun.glass.ui.mac.MacApplication._enterNestedEventLoopImpl(Native Method)
	at com.sun.glass.ui.mac.MacApplication._enterNestedEventLoop(MacApplication.java:113)
	at com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:495)
	at com.sun.glass.ui.EventLoop.enter(EventLoop.java:107)
	at com.sun.glass.ui.mac.MacCommonDialogs._showFileOpenChooser(Native Method)
	at com.sun.glass.ui.mac.MacCommonDialogs.showFileChooser_impl(MacCommonDialogs.java:59)
	at com.sun.glass.ui.mac.MacApplication.staticCommonDialogs_showFileChooser(MacApplication.java:264)
	at com.sun.glass.ui.CommonDialogs.showFileChooser(CommonDialogs.java:212)
	at com.sun.javafx.tk.quantum.QuantumToolkit.showFileChooser(QuantumToolkit.java:1424)
	at javafx.stage.FileChooser.showDialog(FileChooser.java:416)
	at javafx.stage.FileChooser.showOpenMultipleDialog(FileChooser.java:373)
	at tests.Test$2.handle(Test.java:48)
	at tests.Test$2.handle(Test.java:43)
	at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
	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:204)
	at javafx.scene.Node.fireEvent(Node.java:8175)
	at javafx.scene.control.Button.fire(Button.java:185)
	at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
	at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
	at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
	at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
	at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
	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:204)
	at javafx.scene.Scene$MouseHandler.process(Scene.java:3746)
	at javafx.scene.Scene$MouseHandler.access$1800(Scene.java:3471)
	at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1695)
	at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2486)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:314)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:243)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:345)
	at com.sun.glass.ui.View.handleMouseEvent(View.java:526)
	at com.sun.glass.ui.View.notifyMouse(View.java:898)

Comments
Observation: The java ���sample��� window can be exited from the JavaFX Application thread and therefore it is getting exited in this case. But the ���FileOpenChooser��� which is a native window need to be exited on event thread. Exception is thrown because exit method is called for ���FileOpenChooser��� window in JavaFX Application Thread. Possible solution: Should try to cancel the FileOpenChooser dialog in the event thread.
22-03-2017

I would prefer the latter (force close immediately), since it is the documented behavior of Platform.exit() and is what applications would expect.
04-03-2014

I think that Platform.exit() should either refuse to exit if it sees an open modal window (which a file chooser is), or force it to close immediately. We will investigate possible solutions for this issue.
04-03-2014

While the steps that lead to the bug make the application unable to exit, I don't think this is a Major issue because it isn't common to try to quit an app while a file chooser is open on the screen. Therefore I'm updating the priority to Medium.
04-03-2014

Note that the exception is thrown only on MacOS. On windows, when you invoke Platform.exit, the file chooser remains opened BUT when you click the file chooser cancel button, the process terminates correctly. BTW, should a call to Platform.exit close opened file chooser if any (both windows and mac) ?
04-03-2014