Presuming that you aren't calling initialize directly from some other thread, and aren't concurrently accessing the menu from some other thread, I agree that adding a runLater shouldn't be needed. So yes, this does seem like our bug. Can you file a bug report at https://bugreport.java.com/ with a complete standalone test case?

-- Kevin

On 9/7/2022 11:57 PM, Daniel Peintner wrote:
Hi Kevin, all,

I investigated further and I think I found the problem (or at least a solution).

In my application I use FXML+Controller approach.

The issue I described arises if in controller.initialize(...).
I update the menu-items of a menu. In my case, the menu list is empty in FXML and while initializing I update the menu with the "recently" opened files so that people can restart their work with files they opened before.

The solution that works in my case is to wrap these menu updates in Platform.runLater() even though I think this should not be needed. Am I right?

public class MyLayoutController extends BorderPane implements Initializable {
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        // updating the menu updates within runLater() does not cause ConcurrentModificationException
        Platform.runLater(() -> {
           // anyhow, I think this should not be needed
           this.menu.getItems().add(new MenuItem("A"));
           this.menu.getItems().add(new MenuItem("B"));
           this.menu.getItems().add(new MenuItem("C"));
        });
    }
}

Is this sufficient to create a bug report?

Thanks,

-- Daniel




On Mon, Sep 5, 2022 at 7:47 PM Kevin Rushforth <kevin.rushfo...@oracle.com> wrote:

    I suspect a JavaFX bug, unless there some other thread not shown
    in your
    stack trace that is modifying any object in the now-live scene graph.

    -- Kevin


    On 9/5/2022 6:34 AM, Daniel Peintner wrote:
    > All,
    >
    > I have a strange issue popping up once in a while.
    > I have an application (FXML+ Controller) that has a "new" button
    > opening a new window. In 99% percent of the cases this works
    just fine.
    >
    > In some rare cases though, stage.show() fails due to a
    > ConcurrentModificationException. Since this issue does not
    happen in
    > my code but rather in JavaFX code I wanted to ask whether there
    is a
    > specific prerequisite I am not aware of or whether this is a bug in
    > JavaFX.
    >
    > Attached the stack trace. Unfortunately I am not able to create a
    > reproducible example that fails always.
    >
    > I am grateful for any tip.
    >
    > Thanks,
    >
    > -- Daniel
    >
    >
    > Exception in thread "JavaFX Application Thread"
    > java.lang.RuntimeException:
    java.lang.reflect.InvocationTargetException
    > at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1857)
    > at
    >
    
javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1724)
    > 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.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:8797)
    > at javafx.scene.control.Button.fire(Button.java:203)
    > at
    >
    
com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:208)
    > at
    >
    com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
    > 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.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:3881)
    > at javafx.scene.Scene.processMouseEvent(Scene.java:1874)
    > at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2607)
    > at
    >
    
com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
    > at
    >
    
com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
    > at
    >
    
java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    > at
    >
    
com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
    > at
    >
    
com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
    > at
    >
    
com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
    > at com.sun.glass.ui.View.handleMouseEvent(View.java:551)
    > at com.sun.glass.ui.View.notifyMouse(View.java:937)
    > at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    > at
    >
    
com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    > at java.base/java.lang.Thread.run(Thread.java:833)
    > Caused by: java.lang.reflect.InvocationTargetException
    > at
    >
    java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native

    > Method)
    > at
    >
    
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    > at
    >
    
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    > at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    > at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:77)
    > at
    >
    java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native

    > Method)
    > at
    >
    
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    > at
    >
    
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    > at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    > at com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:275)
    > at com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:84)
    > at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1854)
    > ... 50 more
    > Caused by: java.util.ConcurrentModificationException
    > at
    >
    
java.base/java.util.AbstractList$Itr.checkForComodification(AbstractList.java:399)
    > at java.base/java.util.AbstractList$Itr.next(AbstractList.java:368)
    > at
    >
    
javafx.scene.control.skin.MenuBarSkin.updateActionListeners(MenuBarSkin.java:810)
    > at
    >
    
javafx.scene.control.skin.MenuBarSkin.updateActionListeners(MenuBarSkin.java:811)
    > at
    javafx.scene.control.skin.MenuBarSkin.rebuildUI(MenuBarSkin.java:1017)
    > at
    javafx.scene.control.skin.MenuBarSkin.<init>(MenuBarSkin.java:356)
    > at javafx.scene.control.MenuBar.createDefaultSkin(MenuBar.java:202)
    > at javafx.scene.control.Control.doProcessCSS(Control.java:899)
    > at javafx.scene.control.Control$1.doProcessCSS(Control.java:89)
    > at
    >
    
com.sun.javafx.scene.control.ControlHelper.processCSSImpl(ControlHelper.java:67)
    > at com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:146)
    > at javafx.scene.Parent.doProcessCSS(Parent.java:1400)
    > at javafx.scene.Parent$1.doProcessCSS(Parent.java:125)
    > at
    com.sun.javafx.scene.ParentHelper.processCSSImpl(ParentHelper.java:98)
    > at com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:146)
    > at javafx.scene.Parent.doProcessCSS(Parent.java:1400)
    > at javafx.scene.Parent$1.doProcessCSS(Parent.java:125)
    > at
    com.sun.javafx.scene.ParentHelper.processCSSImpl(ParentHelper.java:98)
    > at com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:146)
    > at javafx.scene.Parent.doProcessCSS(Parent.java:1400)
    > at javafx.scene.Parent$1.doProcessCSS(Parent.java:125)
    > at
    com.sun.javafx.scene.ParentHelper.processCSSImpl(ParentHelper.java:98)
    > at com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:146)
    > at javafx.scene.Node.processCSS(Node.java:9477)
    > at javafx.scene.Scene.doCSSPass(Scene.java:572)
    > at javafx.scene.Scene.preferredSize(Scene.java:1770)
    > at javafx.scene.Scene$2.preferredSize(Scene.java:396)
    > at
    com.sun.javafx.scene.SceneHelper.preferredSize(SceneHelper.java:66)
    > at javafx.stage.Window$12.invalidated(Window.java:1163)
    > 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:1239)
    > at javafx.stage.Window.show(Window.java:1254)
    > at javafx.stage.Stage.show(Stage.java:277)
    > at
    >
    com.foo.MainLayoutController.openNewWindow(MainLayoutController.java:3851)
    >
    >
    >
    >
    >
    >

Reply via email to