Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8273573

ActionListenerCalledTwiceTest.java fails on macOS 12

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 17, 18
    • Fix Version/s: 18
    • Component/s: client-libs
    • Labels:

      Description

      javax/swing/JMenuItem/ActionListenerCalledTwice/ActionListenerCalledTwiceTest.java is repeatedly failing on macOS 12

      https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/Desktop.html#setDefaultMenuBar(javax.swing.JMenuBar)

      provides a menu bar that can still be accessed when there are no active frames.
      This is using the system menu bar on maOS and was implemented as part of https://openjdk.java.net/jeps/272

      The test effectively runs twice once with the window active and again iconified.
      It is the latter which fails because no events are delivered and we get

      Exception in thread "main" java.lang.Exception: DefaultMenuBar Test failed: ActionListener for Item1 called 0 times instead of 1!
          at ActionListenerCalledTwiceTest.testForTwice(ActionListenerCalledTwiceTest.java:114)
          at ActionListenerCalledTwiceTest.main(ActionListenerCalledTwiceTest.java:48)

      It appears that in this test when the app is in the iconfied state the test is expecting the keystrokes to go
      to this menu bar still. I don't know if the expecation is correct, but this isn't happening and worked in earlier versions of macOS

      Also I noticed that the test doesn't exit. It appears that the call to

      Desktop.getDesktop().setDefaultMenuBar(bar);

      is effectively creating another visible window so the AWT thread doesn't exit.

      Adding this line below allows the test to exit and should be added to the test
                  SwingUtilities.invokeAndWait(() -> Desktop.getDesktop().setDefaultMenuBar(null));

      One thing it I noticed tho' i that the spec of this method doesn't actually say null is allowed ..
      It might be a good idea to update it - probably as a separate bug since any fix to this may need
      to be backported.

        Attachments

          Activity

            People

            Assignee:
            azvegint Alexander Zvegintsev
            Reporter:
            prr Philip Race
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: