<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    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
    <a class="moz-txt-link-freetext" href="https://bugreport.java.com/">https://bugreport.java.com/</a> with a complete standalone test case?<br>
    <br>
    -- Kevin<br>
    <br>
    <div class="moz-cite-prefix">On 9/7/2022 11:57 PM, Daniel Peintner
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CAAoP7T74BXGLd=5gG9LHjWWc0Jum1GQEsb0me1CK_Pt5HG-_PA@mail.gmail.com">
      
      <div dir="ltr">
        <div>Hi Kevin, all,</div>
        <div><br>
        </div>
        <div>I investigated further and I think I found the problem (or
          at least a solution).</div>
        <div><br>
        </div>
        <div>In my application I use FXML+Controller approach.</div>
        <div><br>
        </div>
        <div>The issue I described arises if in
          controller.initialize(...).</div>
        <div>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.<br>
          <br>
          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?<br>
        </div>
        <div><br>
        </div>
        <div>public class MyLayoutController extends BorderPane
          implements Initializable {</div>
        <div>    @Override<br>
              public void initialize(URL location, ResourceBundle
          resources) {<br>
                  // updating the menu updates within runLater() does
          not cause ConcurrentModificationException<br>
                  Platform.runLater(() -> {<br>
                     // anyhow, I think this should not be needed<br>
                     this.menu.getItems().add(new MenuItem("A"));<br>
                     this.menu.getItems().add(new MenuItem("B"));<br>
                     this.menu.getItems().add(new MenuItem("C"));<br>
                  });<br>
              }<br>
          }<br>
          <br>
          Is this sufficient to create a bug report?<br>
          <br>
          Thanks,<br>
          <br>
          -- Daniel</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Mon, Sep 5, 2022 at 7:47 PM
          Kevin Rushforth <<a href="mailto:kevin.rushforth@oracle.com" moz-do-not-send="true" class="moz-txt-link-freetext">kevin.rushforth@oracle.com</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I
          suspect a JavaFX bug, unless there some other thread not shown
          in your <br>
          stack trace that is modifying any object in the now-live scene
          graph.<br>
          <br>
          -- Kevin<br>
          <br>
          <br>
          On 9/5/2022 6:34 AM, Daniel Peintner wrote:<br>
          > All,<br>
          ><br>
          > I have a strange issue popping up once in a while.<br>
          > I have an application (FXML+ Controller) that has a "new"
          button <br>
          > opening a new window. In 99% percent of the cases this
          works just fine.<br>
          ><br>
          > In some rare cases though, stage.show() fails due to a <br>
          > ConcurrentModificationException. Since this issue does
          not happen in <br>
          > my code but rather in JavaFX code I wanted to ask whether
          there is a <br>
          > specific prerequisite I am not aware of or whether this
          is a bug in <br>
          > JavaFX.<br>
          ><br>
          > Attached the stack trace. Unfortunately I am not able to
          create a <br>
          > reproducible example that fails always.<br>
          ><br>
          > I am grateful for any tip.<br>
          ><br>
          > Thanks,<br>
          ><br>
          > -- Daniel<br>
          ><br>
          ><br>
          > Exception in thread "JavaFX Application Thread" <br>
          > java.lang.RuntimeException:
          java.lang.reflect.InvocationTargetException<br>
          > at
          javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1857)<br>
          > at <br>
          >
javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1724)<br>
          > at <br>
          >
com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)<br>
          > at <br>
          >
com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)<br>
          > at <br>
          >
com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)<br>
          > at <br>
          >
com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)<br>
          > at <br>
          >
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)<br>
          > at <br>
          >
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)<br>
          > at <br>
          >
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)<br>
          > at <br>
          >
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)<br>
          > at <br>
          >
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)<br>
          > at <br>
          >
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)<br>
          > at <br>
          >
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)<br>
          > at <br>
          >
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)<br>
          > at
          com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)<br>
          > at
          com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)<br>
          > at javafx.event.Event.fireEvent(Event.java:198)<br>
          > at javafx.scene.Node.fireEvent(Node.java:8797)<br>
          > at javafx.scene.control.Button.fire(Button.java:203)<br>
          > at <br>
          >
com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:208)<br>
          > at <br>
          >
          com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)<br>
          > at <br>
          >
com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)<br>
          > at <br>
          >
com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)<br>
          > at <br>
          >
com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)<br>
          > at <br>
          >
com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)<br>
          > at <br>
          >
com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)<br>
          > at <br>
          >
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)<br>
          > at <br>
          >
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)<br>
          > at <br>
          >
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)<br>
          > at <br>
          >
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)<br>
          > at <br>
          >
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)<br>
          > at <br>
          >
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)<br>
          > at <br>
          >
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)<br>
          > at <br>
          >
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)<br>
          > at
          com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)<br>
          > at
          com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)<br>
          > at javafx.event.Event.fireEvent(Event.java:198)<br>
          > at
          javafx.scene.Scene$MouseHandler.process(Scene.java:3881)<br>
          > at javafx.scene.Scene.processMouseEvent(Scene.java:1874)<br>
          > at
          javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2607)<br>
          > at <br>
          >
com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)<br>
          > at <br>
          >
com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)<br>
          > at <br>
          >
java.base/java.security.AccessController.doPrivileged(AccessController.java:399)<br>
          > at <br>
          >
com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)<br>
          > at <br>
          >
com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)<br>
          > at <br>
          >
com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)<br>
          > at com.sun.glass.ui.View.handleMouseEvent(View.java:551)<br>
          > at com.sun.glass.ui.View.notifyMouse(View.java:937)<br>
          > at com.sun.glass.ui.win.WinApplication._runLoop(Native
          Method)<br>
          > at <br>
          >
com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)<br>
          > at java.base/java.lang.Thread.run(Thread.java:833)<br>
          > Caused by: java.lang.reflect.InvocationTargetException<br>
          > at <br>
          >
          java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
          <br>
          > Method)<br>
          > at <br>
          >
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)<br>
          > at <br>
          >
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)<br>
          > at
          java.base/java.lang.reflect.Method.invoke(Method.java:568)<br>
          > at
          com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:77)<br>
          > at <br>
          >
          java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
          <br>
          > Method)<br>
          > at <br>
          >
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)<br>
          > at <br>
          >
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)<br>
          > at
          java.base/java.lang.reflect.Method.invoke(Method.java:568)<br>
          > at
          com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:275)<br>
          > at
          com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:84)<br>
          > at
          javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1854)<br>
          > ... 50 more<br>
          > Caused by: java.util.ConcurrentModificationException<br>
          > at <br>
          >
java.base/java.util.AbstractList$Itr.checkForComodification(AbstractList.java:399)<br>
          > at
          java.base/java.util.AbstractList$Itr.next(AbstractList.java:368)<br>
          > at <br>
          >
javafx.scene.control.skin.MenuBarSkin.updateActionListeners(MenuBarSkin.java:810)<br>
          > at <br>
          >
javafx.scene.control.skin.MenuBarSkin.updateActionListeners(MenuBarSkin.java:811)<br>
          > at
          javafx.scene.control.skin.MenuBarSkin.rebuildUI(MenuBarSkin.java:1017)<br>
          > at
          javafx.scene.control.skin.MenuBarSkin.<init>(MenuBarSkin.java:356)<br>
          > at
          javafx.scene.control.MenuBar.createDefaultSkin(MenuBar.java:202)<br>
          > at
          javafx.scene.control.Control.doProcessCSS(Control.java:899)<br>
          > at
          javafx.scene.control.Control$1.doProcessCSS(Control.java:89)<br>
          > at <br>
          >
com.sun.javafx.scene.control.ControlHelper.processCSSImpl(ControlHelper.java:67)<br>
          > at
          com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:146)<br>
          > at javafx.scene.Parent.doProcessCSS(Parent.java:1400)<br>
          > at javafx.scene.Parent$1.doProcessCSS(Parent.java:125)<br>
          > at
          com.sun.javafx.scene.ParentHelper.processCSSImpl(ParentHelper.java:98)<br>
          > at
          com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:146)<br>
          > at javafx.scene.Parent.doProcessCSS(Parent.java:1400)<br>
          > at javafx.scene.Parent$1.doProcessCSS(Parent.java:125)<br>
          > at
          com.sun.javafx.scene.ParentHelper.processCSSImpl(ParentHelper.java:98)<br>
          > at
          com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:146)<br>
          > at javafx.scene.Parent.doProcessCSS(Parent.java:1400)<br>
          > at javafx.scene.Parent$1.doProcessCSS(Parent.java:125)<br>
          > at
          com.sun.javafx.scene.ParentHelper.processCSSImpl(ParentHelper.java:98)<br>
          > at
          com.sun.javafx.scene.NodeHelper.processCSS(NodeHelper.java:146)<br>
          > at javafx.scene.Node.processCSS(Node.java:9477)<br>
          > at javafx.scene.Scene.doCSSPass(Scene.java:572)<br>
          > at javafx.scene.Scene.preferredSize(Scene.java:1770)<br>
          > at javafx.scene.Scene$2.preferredSize(Scene.java:396)<br>
          > at
          com.sun.javafx.scene.SceneHelper.preferredSize(SceneHelper.java:66)<br>
          > at javafx.stage.Window$12.invalidated(Window.java:1163)<br>
          > at <br>
          >
javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110)<br>
          > at <br>
          >
javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:145)<br>
          > at javafx.stage.Window.setShowing(Window.java:1239)<br>
          > at javafx.stage.Window.show(Window.java:1254)<br>
          > at javafx.stage.Stage.show(Stage.java:277)<br>
          > at <br>
          >
com.foo.MainLayoutController.openNewWindow(MainLayoutController.java:3851)<br>
          ><br>
          ><br>
          ><br>
          ><br>
          ><br>
          ><br>
          <br>
        </blockquote>
      </div>
    </blockquote>
    <br>
  </body>
</html>