JDK-8004148 : NPE in sun.awt.SunToolkit.getWindowDeactivationTime
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u10,8
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • Submitted: 2012-11-29
  • Updated: 2021-07-06
  • Resolved: 2014-11-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9 Other
8u301Fixed 9 b42Fixed openjdk8u312Fixed
Related Reports
Duplicate :  
Description
Stacktrace: 
java.lang.NullPointerException
   at sun.awt.SunToolkit.getWindowDeactivationTime(SunToolkit.java:1878)
   at
com.sun.java.swing.plaf.windows.WindowsRootPaneUI$AltProcessor.altReleased(WindowsRootPaneUI.java:139)
   at
com.sun.java.swing.plaf.windows.WindowsRootPaneUI$AltProcessor.postProcessKeyEvent(WindowsRootPaneUI.java:178)
   at
java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:807)
   at
java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1056)
   at
java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:931)

http://netbeans.org/bugzilla/show_bug.cgi?id=222890

Comments
Fix Request (8u) I would like to backport this patch to openjdk8u for parity with Oracle 8u301. 8u patch has been reviewed.
28-06-2021

8u code review: https://mail.openjdk.java.net/pipermail/jdk8u-dev/2021-June/014027.html
25-06-2021

The following test covers the issue, written for JDK-8001633, which had been integrated before: test/javax/swing/plaf/windows/WindowsRootPaneUI/WrongAltProcessing/WrongAltProcessing.java
14-11-2014

webrev: http://cr.openjdk.java.net/~ant/JDK-8004148/webrev.0
07-11-2014

At the same time, in the SunToolkit.getWindowDeactivationTime(Window) method there should be a check for null input. Probably, the cause of the original Netbeans issue (no test case is provided) differs. Anyway, the method should return -1 for null window. I'll request for the backport of JDK-8001633.
07-11-2014

The thing is this. The NPE is caused by dereferencing null AppContext at this code snippet: public synchronized long getWindowDeactivationTime(Window w) { AppContext ctx = getAppContext(w); WeakHashMap<Window, Long> map = (WeakHashMap<Window, Long>)ctx.get(DEACTIVATION_TIMES_MAP_KEY); The AppContext is null here simply because the "w" is null as well. The origination of the "w" value is from WindowsRootPaneUI which computes it as winAncestor: root = SwingUtilities.getRootPane(ev.getComponent()); winAncestor = (root == null ? null : SwingUtilities.getWindowAncestor(root)); However, no JRootPane exists for a pure AWT Frame created in the test case. But the swing L&F stuff forced by the test brings the WindowsRootPaneUI to the scene (I have no idea what's the real purpose of this). The bug is not reproduced since jdk8 because of the fix for JDK-8001633 which doesn't call SunToolkit.getWindowDeactivationTime(Window) with null parameter.
07-11-2014

It's not reproducible with the latest 8u40 and 9, but with 7u60. Here's the test case kindly provided by Eiji Suzuki: (1) Compile TestFrameAltKey.java (See below). (2) run TestFrameAltKey.class on JDK7. (3) Push "Alt" key. Then, you will see NPE on the console. import java.awt.Frame; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class TestFrameAltKey { public static void main(String args[]){ try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Throwable the) { the.printStackTrace(); } Frame frame = new Frame(); frame.setSize(400,400); frame.setVisible(true); } }
07-11-2014

Related to 6981400: Tabbing between textfield do not work properly when ALT+TAB 7157015: [macosx] Situation when KeyEventDispatcher doesn't work on AWT but does on Swing. 7121442: Regression : Reopen CR 6458497 still reproducible using JDK 7.
17-07-2013