JDK-8095460 : ConcurrentModificationException when closing a dialog from a context menu of a textfield.
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 8u40
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2015-04-13
  • Updated: 2015-06-12
  • Resolved: 2015-04-17
Related Reports
Duplicate :  
Description
Run the following example app:

	import javafx.application.Application;
	import javafx.event.ActionEvent;
	import javafx.event.EventHandler;
	import javafx.scene.Node;
	import javafx.scene.Scene;
	import javafx.scene.control.ButtonType;
	import javafx.scene.control.Dialog;
	import javafx.scene.control.Menu;
	import javafx.scene.control.MenuBar;
	import javafx.scene.control.MenuItem;
	import javafx.scene.control.TextArea;
	import javafx.scene.input.KeyCombination;
	import javafx.scene.layout.Priority;
	import javafx.scene.layout.VBox;
	import javafx.stage.Stage;
	
	public class DialogConcurrentModification extends Application {
	
		private class MyDialog extends Dialog<Void> {
	
			public MyDialog() {
				setTitle("Test");
				getDialogPane().setContent(createPresentation());
				getDialogPane().getButtonTypes().addAll(ButtonType.CLOSE);
			}
	
			private TextArea output = new TextArea() {
				public void copy() {
					super.copy();
					close();
				};
			};
	
			private Node createPresentation() {
				VBox vbox = new VBox();
				output.setText("Test 123");
				output.setEditable(false);
				output.prefWidthProperty().bind(vbox.widthProperty());
				output.setPrefHeight(300);
				output.selectAll();
				VBox.setVgrow(output, Priority.ALWAYS);
				vbox.getChildren().addAll(output);
				return vbox;
			}
		}
	
		public DialogConcurrentModification() {
		}
	
		@Override
		public void start(Stage stage) throws Exception {
			stage.setTitle("DialogConcurrentModification");
			Scene scene = new Scene(new VBox(), 400, 350);
	
			MenuBar menuBar = new MenuBar();
	
			// --- Menu File
			Menu menuFile = new Menu("File");
			menuBar.getMenus().addAll(menuFile);
	
			MenuItem test = new MenuItem("Open Dialog");
			test.setAccelerator(KeyCombination.keyCombination("Ctrl+O"));
			test.setOnAction(new EventHandler<ActionEvent>() {
				public void handle(ActionEvent t) {
					Dialog<Void> dlg = new MyDialog();
					dlg.showAndWait();
				}
			});
	
			menuFile.getItems().add(test);
	
			((VBox) scene.getRoot()).getChildren().addAll(menuBar);
	
			stage.setScene(scene);
			stage.show();
		}
	
		public static void main(String[] args) {
			launch(args);
		}
	}

Open the dialog (Ctrl+O), then right-click into the textarea and select "copy" from the context-menu. This should copy the text into the clipboard and close the dialog.

Under Windows (and only there) an Exception is thrown however:
Exception in thread "JavaFX Application Thread" java.util.ConcurrentModificationException
	at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
	at java.util.ArrayList$Itr.next(ArrayList.java:851)
	at com.sun.javafx.tk.quantum.GlassStage.windowsSetEnabled(GlassStage.java:166)
	at com.sun.javafx.tk.quantum.WindowStage.setVisible(WindowStage.java:438)
	at javafx.stage.Window$9.invalidated(Window.java:791)
	at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:109)
	at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:143)
	at javafx.stage.Window.setShowing(Window.java:841)
	at javafx.stage.Window.hide(Window.java:866)
	at javafx.scene.control.HeavyweightDialog.close(HeavyweightDialog.java:205)
	at javafx.scene.control.Dialog.close(Dialog.java:349)
	at prv.rli.codetest.DialogConcurrentModification$MyDialog$1.copy(DialogConcurrentModification.java:32)
	at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callAction(TextInputControlBehavior.java:165)
	at com.sun.javafx.scene.control.behavior.TextAreaBehavior.callAction(TextAreaBehavior.java:255)
	at com.sun.javafx.scene.control.skin.TextInputControlSkin$ContextMenuItem.lambda$new$190(TextInputControlSkin.java:671)
	at com.sun.javafx.scene.control.skin.TextInputControlSkin$ContextMenuItem$$Lambda$215/400489718.handle(Unknown Source)
	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.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
	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.control.MenuItem.fire(MenuItem.java:462)
	at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1364)
	at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.lambda$createChildren$324(ContextMenuContent.java:1317)
	at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer$$Lambda$282/1216030339.handle(Unknown Source)
	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.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.Scene$MouseHandler.process(Scene.java:3724)
	at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3452)
	at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1728)
	at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2461)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:348)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:273)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:382)
	at com.sun.glass.ui.View.handleMouseEvent(View.java:553)
	at com.sun.glass.ui.View.notifyMouse(View.java:925)
	at com.sun.glass.ui.win.WinApplication._enterNestedEventLoopImpl(Native Method)
	at com.sun.glass.ui.win.WinApplication._enterNestedEventLoop(WinApplication.java:129)
	at com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:513)
	at com.sun.glass.ui.EventLoop.enter(EventLoop.java:107)
	at com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:519)
	at javafx.stage.Stage.showAndWait(Stage.java:462)
	at javafx.scene.control.HeavyweightDialog.showAndWait(HeavyweightDialog.java:200)
	at javafx.scene.control.Dialog.showAndWait(Dialog.java:295)
	at prv.rli.codetest.DialogConcurrentModification$1.handle(DialogConcurrentModification.java:68)
	at prv.rli.codetest.DialogConcurrentModification$1.handle(DialogConcurrentModification.java:1)
	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.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
	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.control.MenuItem.fire(MenuItem.java:462)
	at com.sun.javafx.scene.control.ControlAcceleratorSupport.lambda$doAcceleratorInstall$12(ControlAcceleratorSupport.java:163)
	at com.sun.javafx.scene.control.ControlAcceleratorSupport$$Lambda$119/148261540.run(Unknown Source)
	at com.sun.javafx.scene.KeyboardShortcutsHandler.processAccelerators(KeyboardShortcutsHandler.java:348)
	at com.sun.javafx.scene.KeyboardShortcutsHandler.dispatchBubblingEvent(KeyboardShortcutsHandler.java:166)
	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.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$KeyHandler.process(Scene.java:3931)
	at javafx.scene.Scene$KeyHandler.access$1800(Scene.java:3877)
	at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2006)
	at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2468)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:197)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:147)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:227)
	at com.sun.glass.ui.View.handleKeyEvent(View.java:544)
	at com.sun.glass.ui.View.notifyKey(View.java:954)
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
	at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source)
	at java.lang.Thread.run(Thread.java:745)

Comments
I can confirm that this is a duplicate of RT-39569. Once that issue is fixed, I will run your test case to verify that it is fixed.
17-04-2015

I am pretty sure that is a duplicate of RT-39569 which I plan to fix in 8u60. I will confirm.
13-04-2015

If I modify the TextArea copy-method like this: private TextArea output = new TextArea() { public void copy() { super.copy(); Platform.runLater(() -> { Platform.runLater(() -> { close(); }); }); }; }; the exception goes away...
13-04-2015