title: NullPointerException at java.awt.EventQueue.getCurrentEventImpl
body: <p>I've migrated a Swing application to Java 8 and recently we see the following NPE exception. </p>
  
  <pre><code>java.lang.NullPointerException
  at java.awt.EventQueue.getCurrentEventImpl(EventQueue.java:848)
  at java.awt.EventQueue.getCurrentEvent(EventQueue.java:842)
  at java.awt.Component.requestFocusHelper(Component.java:7628)
  at java.awt.Component.requestFocusHelper(Component.java:7620)
  at java.awt.Component.requestFocus(Component.java:7495)
  at javax.swing.JComponent.requestFocus(JComponent.java:1504)
  at javax.swing.plaf.basic.BasicPopupMenuUI$MenuKeyboardHelper.stateChanged(BasicPopupMenuUI.java:1173)
  at javax.swing.MenuSelectionManager.fireStateChanged(MenuSelectionManager.java:202)
  at javax.swing.MenuSelectionManager.setSelectedPath(MenuSelectionManager.java:129)
  at javax.swing.JPopupMenu.setVisible(JPopupMenu.java:784)
  at javax.swing.JPopupMenu.show(JPopupMenu.java:965)
  at org.tbee.swing.StandardComponentPopupMenu.showJTableMenu(StandardComponentPopupMenu.java:555)
  at org.tbee.swing.StandardComponentPopupMenu$2.run(StandardComponentPopupMenu.java:175)
  at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
  at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
  at java.awt.EventQueue.access$500(EventQueue.java:97)
  at java.awt.EventQueue$3.run(EventQueue.java:709)
  at java.awt.EventQueue$3.run(EventQueue.java:703)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
  at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
  at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
  </code></pre>
  
  <p>Migrating back to J7 is a problem, because lambda's are being used, so I cannot easily confirm that this really is a J8 issue. But the code in question has been running for several years now, surviving Java 5, 6 and 7. So chances are it is J8 specific.</p>
  
  <p>The reason for the exception is that currentEvent in EventQueue is not set. This is done by its setCurrentEventAndMostRecentTimeImpl(AWTEvent e). However, if I trace back in the stack, I see that in EventQueue:756 (Java 1.8.0u45) the dispatch is done after exactly that method is called.</p>
  
  <pre><code>    if (event instanceof ActiveEvent) {
          // This could become the sole method of dispatching in time.
          setCurrentEventAndMostRecentTimeImpl(event);
          ((ActiveEvent)event).dispatch();
  </code></pre>
  
  <p>I'm in the dark why that variable is null. Debugging is close to impossible, because of all the events being handled by that piece of code.</p>
  
  <p>Is anyone aware of changes in Swing's event handling in J8?</p>