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

[macos] "java.lang.RuntimeException: Event posted on wrong app context" in SystemTray

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • 9, 10
    • client-libs
    • generic
    • os_x

      When the user click on the trayicon we can get an exception instead of ActionEvent.
      =======
      import java.awt.Color;
      import java.awt.Graphics2D;
      import java.awt.SystemTray;
      import java.awt.TrayIcon;
      import java.awt.event.MouseAdapter;
      import java.awt.event.MouseEvent;
      import java.awt.image.BufferedImage;

      public final class TrayTest {

          public static void main(final String[] args) {
              SystemTray st = SystemTray.getSystemTray();
              BufferedImage image =
                      new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB);
              Graphics2D graphics = image.createGraphics();
              graphics.setColor(Color.RED);
              graphics.fillRect(0, 0, 20, 20);
              TrayIcon icon = new TrayIcon(image, "caption");
              TrayIcon icon1 = new TrayIcon(image, "caption");
              icon.addActionListener(event -> {
                  System.out.println("event = " + event);
              });
              icon.addMouseListener(new MouseAdapter() {
                  @Override
                  public void mousePressed(MouseEvent mouseEvent) {
                      super.mousePressed(mouseEvent);
                      try {
                          icon.displayMessage("Caption1", "Text",
                                              TrayIcon.MessageType.ERROR);
                          Thread.sleep(1000);
                          icon.displayMessage("Caption2", "Text",
                                              TrayIcon.MessageType.INFO);
                          Thread.sleep(1000);
                          icon.displayMessage("Caption3", "Text",
                                              TrayIcon.MessageType.NONE);
                          Thread.sleep(1000);
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      }
                      icon.displayMessage("Caption4", "Text",
                                          TrayIcon.MessageType.WARNING);
                      st.remove(icon);
                  }
              });
              icon1.addMouseListener(new MouseAdapter() {
                  @Override
                  public void mousePressed(MouseEvent mouseEvent) {
                      super.mousePressed(mouseEvent);

                      try {
                          icon1.displayMessage("Caption1", "Text",
                                              TrayIcon.MessageType.ERROR);
                          Thread.sleep(1000);
                          icon1.displayMessage("Caption2", "Text",
                                              TrayIcon.MessageType.INFO);
                          Thread.sleep(1000);
                          icon1.displayMessage("Caption3", "Text",
                                              TrayIcon.MessageType.NONE);
                          Thread.sleep(1000);
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      }
                      icon1.displayMessage("Caption4", "Text",
                                          TrayIcon.MessageType.WARNING);
                      st.remove(icon1);
                  }
              });
              try {
                  st.add(icon);
                  st.add(icon1);
              } catch (Exception e) {
                  throw new RuntimeException(e);
              }
          }
      }

      =======
      Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Event posted on wrong app context : java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=null,when=0,modifiers=] on java.awt.TrayIcon@3632be31
      at java.desktop/sun.awt.SunToolkit.postEvent(SunToolkit.java:421)
      at java.desktop/sun.lwawt.macosx.CTrayIcon$2.run(CTrayIcon.java:210)
      at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
      at java.desktop/java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:717)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:711)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:99)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:741)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:739)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:738)
      at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
      Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Event posted on wrong app context : java.awt.event.MouseEvent[MOUSE_RELEASED,(795,10),absolute(795,10),button=3,modifiers=⌘+Button3,clickCount=1] on java.awt.TrayIcon@3632be31
      at java.desktop/sun.awt.SunToolkit.postEvent(SunToolkit.java:421)
      at java.desktop/sun.lwawt.macosx.CTrayIcon$2.run(CTrayIcon.java:210)
      at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
      at java.desktop/java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:717)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:711)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:99)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:741)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:739)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:738)
      at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
      Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Event posted on wrong app context : java.awt.event.MouseEvent[MOUSE_CLICKED,(795,10),absolute(795,10),button=3,modifiers=⌘+Button3,clickCount=1] on java.awt.TrayIcon@3632be31
      at java.desktop/sun.awt.SunToolkit.postEvent(SunToolkit.java:421)
      at java.desktop/sun.lwawt.macosx.CTrayIcon$2.run(CTrayIcon.java:210)
      at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
      at java.desktop/java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:717)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:711)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:99)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:741)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:739)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:738)
      at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
      Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Event posted on wrong app context : java.awt.event.MouseEvent[MOUSE_MOVED,(795,10),absolute(795,10),clickCount=0] on java.awt.TrayIcon@3632be31
      at java.desktop/sun.awt.SunToolkit.postEvent(SunToolkit.java:421)
      at java.desktop/sun.lwawt.macosx.CTrayIcon$2.run(CTrayIcon.java:210)
      at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
      at java.desktop/java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:717)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:711)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:99)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:741)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:739)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:738)
      at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
      Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Event posted on wrong app context : java.awt.event.MouseEvent[MOUSE_MOVED,(794,18),absolute(794,18),clickCount=0] on java.awt.TrayIcon@3632be31
      at java.desktop/sun.awt.SunToolkit.postEvent(SunToolkit.java:421)
      at java.desktop/sun.lwawt.macosx.CTrayIcon$2.run(CTrayIcon.java:210)
      at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
      at java.desktop/java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:717)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:711)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:99)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:741)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:739)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:738)
      at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
      Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Event posted on wrong app context : java.awt.event.MouseEvent[MOUSE_MOVED,(788,10),absolute(788,10),clickCount=0] on java.awt.TrayIcon@3632be31
      at java.desktop/sun.awt.SunToolkit.postEvent(SunToolkit.java:421)
      at java.desktop/sun.lwawt.macosx.CTrayIcon$2.run(CTrayIcon.java:210)
      at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
      at java.desktop/java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:717)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:711)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:99)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:741)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:739)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:738)
      at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
      Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Event posted on wrong app context : java.awt.event.MouseEvent[MOUSE_MOVED,(790,10),absolute(790,10),clickCount=0] on java.awt.TrayIcon@3632be31
      at java.desktop/sun.awt.SunToolkit.postEvent(SunToolkit.java:421)
      at java.desktop/sun.lwawt.macosx.CTrayIcon$2.run(CTrayIcon.java:210)
      at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
      at java.desktop/java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:717)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:711)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:99)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:741)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:739)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:738)
      at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
      Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Event posted on wrong app context : java.awt.event.MouseEvent[MOUSE_MOVED,(792,10),absolute(792,10),clickCount=0] on java.awt.TrayIcon@3632be31
      at java.desktop/sun.awt.SunToolkit.postEvent(SunToolkit.java:421)
      at java.desktop/sun.lwawt.macosx.CTrayIcon$2.run(CTrayIcon.java:210)
      at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
      at java.desktop/java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:717)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:711)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:99)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:741)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:739)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:738)
      at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
      Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Event posted on wrong app context : java.awt.event.MouseEvent[MOUSE_MOVED,(794,10),absolute(794,10),clickCount=0] on java.awt.TrayIcon@3632be31
      at java.desktop/sun.awt.SunToolkit.postEvent(SunToolkit.java:421)
      at java.desktop/sun.lwawt.macosx.CTrayIcon$2.run(CTrayIcon.java:210)
      at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
      at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
      at java.desktop/java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:717)
      at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:711)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:99)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:741)
      at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:739)
      at java.base/java.security.AccessController.doPrivileged(Native Method)
      at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
      at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:738)
      at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
      at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
      at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

            Unassigned Unassigned
            serb Sergey Bylokhov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: