Alert(对话框)中的JavaFX ConcurrentModificationException

时间:2016-03-22 08:21:53

标签: java javafx

在我的JavaFX应用程序中,我显示了一个确认对话框(该方法位于MainController类中,并在主JavaFX线程上执行:

/**
 * Shows a simple confirmation Dialog with ok/cancel button
 *
 * @param message the text inside the windows
 * @return An The answer of the user
 */
private Optional<ButtonType> showConfirmDialog(String message) {
    Alert alert = new Alert(AlertType.CONFIRMATION);
    ButtonType buttonYes = new ButtonType(Messages.YES, ButtonData.YES);
    ButtonType buttonNo = new ButtonType(Messages.CANCEL, ButtonData.CANCEL_CLOSE);
    alert.getButtonTypes().setAll(buttonYes, buttonNo);

    // make focuses button default button (-> which is fired when pressing enter)
    Button noButton = (Button) alert.getDialogPane().lookupButton(buttonNo);
    noButton.defaultButtonProperty().bind(noButton.focusedProperty());
    Button yesButton = (Button) alert.getDialogPane().lookupButton(buttonYes);
    yesButton.defaultButtonProperty().bind(yesButton.focusedProperty());

    alert.setTitle(null);
    alert.setHeaderText(message);
    return alert.showAndWait(); // line 1260
}

请注意,我将默认按钮绑定到焦点按钮,如下所述:https://stackoverflow.com/a/29536464/1138523。一次,我得到以下ConcurrentModificationException

java.util.ConcurrentModificationException
    at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901) ~[?:1.8.0_51]
    at java.util.ArrayList$Itr.next(ArrayList.java:851) ~[?:1.8.0_51]
    at com.sun.javafx.tk.quantum.GlassStage.windowsSetEnabled(GlassStage.java:166) ~[jfxrt.jar:?]
    at com.sun.javafx.tk.quantum.WindowStage.setVisible(WindowStage.java:441) ~[jfxrt.jar:?]
    at javafx.stage.Window$9.invalidated(Window.java:860) ~[jfxrt.jar:?]
    at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:109) ~[jfxrt.jar:?]
    at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:144) ~[jfxrt.jar:?]
    at javafx.stage.Window.setShowing(Window.java:910) ~[jfxrt.jar:?]
    at javafx.stage.Window.hide(Window.java:935) ~[jfxrt.jar:?]
    at javafx.scene.control.HeavyweightDialog.close(HeavyweightDialog.java:162) ~[jfxrt.jar:?]
    at javafx.scene.control.Dialog.close(Dialog.java:383) ~[jfxrt.jar:?]
    at javafx.scene.control.Dialog$2.invalidated(Dialog.java:631) ~[jfxrt.jar:?]
    at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:111) ~[jfxrt.jar:?]
    at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146) ~[jfxrt.jar:?]
    at javafx.scene.control.Dialog.setResult(Dialog.java:651) ~[jfxrt.jar:?]
    at javafx.scene.control.Dialog.impl_setResultAndClose(Dialog.java:1001) ~[jfxrt.jar:?]
    at javafx.scene.control.DialogPane.lambda$createButton$602(DialogPane.java:776) ~[jfxrt.jar:?]
    at javafx.scene.control.DialogPane$$Lambda$367/203033415.handle(Unknown Source) ~[?:?]
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218) ~[jfxrt.jar:?]
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) ~[jfxrt.jar:?]
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) ~[jfxrt.jar:?]
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) ~[jfxrt.jar:?]
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) ~[jfxrt.jar:?]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) ~[jfxrt.jar:?]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) ~[jfxrt.jar:?]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) ~[jfxrt.jar:?]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) ~[jfxrt.jar:?]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) ~[jfxrt.jar:?]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) ~[jfxrt.jar:?]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) ~[jfxrt.jar:?]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) ~[jfxrt.jar:?]
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) ~[jfxrt.jar:?]
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) ~[jfxrt.jar:?]
    at javafx.event.Event.fireEvent(Event.java:198) ~[jfxrt.jar:?]
    at javafx.scene.Node.fireEvent(Node.java:8390) ~[jfxrt.jar:?]
    at javafx.scene.control.Button.fire(Button.java:185) ~[jfxrt.jar:?]
    at com.sun.javafx.scene.control.skin.ButtonSkin.lambda$new$279(ButtonSkin.java:102) ~[jfxrt.jar:?]
    at com.sun.javafx.scene.control.skin.ButtonSkin$$Lambda$199/1153218589.run(Unknown Source) ~[?:?]
    at com.sun.javafx.scene.KeyboardShortcutsHandler.processAccelerators(KeyboardShortcutsHandler.java:347) ~[jfxrt.jar:?]
    at com.sun.javafx.scene.KeyboardShortcutsHandler.dispatchBubblingEvent(KeyboardShortcutsHandler.java:163) ~[jfxrt.jar:?]
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) ~[jfxrt.jar:?]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) ~[jfxrt.jar:?]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) ~[jfxrt.jar:?]
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) ~[jfxrt.jar:?]
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) ~[jfxrt.jar:?]
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) ~[jfxrt.jar:?]
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) ~[jfxrt.jar:?]
    at javafx.event.Event.fireEvent(Event.java:198) ~[jfxrt.jar:?]
    at javafx.scene.Scene$KeyHandler.process(Scene.java:3965) ~[jfxrt.jar:?]
    at javafx.scene.Scene$KeyHandler.access$1800(Scene.java:3911) ~[jfxrt.jar:?]
    at javafx.scene.Scene.impl_processKeyEvent(Scene.java:2040) ~[jfxrt.jar:?]
    at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2502) ~[jfxrt.jar:?]
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:197) ~[jfxrt.jar:?]
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:147) ~[jfxrt.jar:?]
    at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_51]
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$349(GlassViewEventHandler.java:228) ~[jfxrt.jar:?]
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$347/1118191065.get(Unknown Source) ~[?:?]
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:404) ~[jfxrt.jar:?]
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:227) ~[jfxrt.jar:?]
    at com.sun.glass.ui.View.handleKeyEvent(View.java:546) ~[jfxrt.jar:?]
    at com.sun.glass.ui.View.notifyKey(View.java:956) ~[jfxrt.jar:?]
    at com.sun.glass.ui.win.WinApplication._enterNestedEventLoopImpl(Native Method) ~[jfxrt.jar:?]
    at com.sun.glass.ui.win.WinApplication._enterNestedEventLoop(WinApplication.java:128) [jfxrt.jar:?]
    at com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:511) [jfxrt.jar:?]
    at com.sun.glass.ui.EventLoop.enter(EventLoop.java:107) [jfxrt.jar:?]
    at com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:593) [jfxrt.jar:?]
    at javafx.stage.Stage.showAndWait(Stage.java:463) [jfxrt.jar:?]
    at javafx.scene.control.HeavyweightDialog.showAndWait(HeavyweightDialog.java:157) [jfxrt.jar:?]
    at javafx.scene.control.Dialog.showAndWait(Dialog.java:313) [jfxrt.jar:?]
    at myApp.MainController.showConfirmDialog(MainController.java:1260) [bin/:?]

只有当我专注于ChoiceBox,然后显示confirmDialog然后按下CANCEL - 按钮

时才会发生这种情况。

有人知道问题是什么吗?也许问题是默认/聚焦按钮的绑定?

1 个答案:

答案 0 :(得分:1)

比较堆栈跟踪时,看起来可能是错误JDK-8096583 : ConcurrentModificationException when closing APPLICATION_MODAL dialog。根据错误报告,它在JDK 1.8.0u60中修复。