JDK-6573198 : PIT: NullPointerException when trying print-to-file from a native print dialog, Win32
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-06-24
  • Updated: 2011-05-18
  • Resolved: 2011-05-18
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 7
7 b17Fixed
Related Reports
Relates :  
Relates :  
Description
Run the attached test. You will get a frame with few buttons. Do the following -

- Click on 'Print Common'. A cross-platform print dialog would appear. 
- Press 'ENTER'. Since 'PrintToFile' is selected, a file dialog will be opened. 
- Either press 'OK' or Cancel the file dialog. 
- Click on 'Print Native' button on the frame. A native print dialog will appear.
- Select 'PrintToFile' checkbox and click 'ok'. 

You will get the NullPointerException which is shown below -
Exception in thread "Thread-3" java.lang.NullPointerException
at sun.awt.windows.WWindowPeer.getActiveWindowHandles(WWindowPeer.java:46)
at sun.awt.windows.WPrintDialogPeer._show(Native Method)
at sun.awt.windows.WPrintDialogPeer.access$000(WPrintDialogPeer.java:35
at sun.awt.windows.WPrintDialogPeer$1.run(WPrintDialogPeer.java:67)
at java.lang.Thread.run(Thread.java:637)

This is reproducible only on Win32. This is reproducible only on JDK7-b15 AWT PIT build and not reproducible on b13 promoted build. Hence it is a regression in b15 PIT.

Comments
SUGGESTED FIX The suggested fix above does eliminate the problem with NPE, however it is not a good fix. The right fix is included to the fix for 4726458.
25-06-2007

SUGGESTED FIX --- WWindowPeer.java 2007-06-25 14:40:18.000000000 +0400 *************** *** 455,463 **** appContext.put(ACTIVE_WINDOWS_KEY, l); } WWindowPeer wp = (WWindowPeer)w.getPeer(); ! // add/move wp to the end of the list ! l.remove(wp); ! l.add(wp); } } } --- 455,466 ---- appContext.put(ACTIVE_WINDOWS_KEY, l); } WWindowPeer wp = (WWindowPeer)w.getPeer(); ! // it's possible that active window has already its peer destroyed ! if (wp != null) { ! // add/move wp to the end of the list ! l.remove(wp); ! l.add(wp); ! } } } }
25-06-2007

EVALUATION While looking at the bug, I found quite another issue: 'activeWindow' property of KeyboardFocusManager is not changed when any native dialog is activated. I'll file a separate bug about this. As for the NPE described, the problem is that 'activeWindow' property change may be sent by KFM when the window peer is already destroyed. After this strange propertyChange, 'null' is added to the list of activated windows and causes the NPE with a subsequent call to getActiveWindowHandles. See suggested fix for details.
25-06-2007