United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6573198 PIT: NullPointerException when trying print-to-file from a native print dialog, Win32
JDK-6573198 : PIT: NullPointerException when trying print-to-file from a native print dialog, Win32

Details
Type:
Bug
Submit Date:
2007-06-24
Status:
Closed
Updated Date:
2011-05-18
Project Name:
JDK
Resolved Date:
2011-05-18
Component:
client-libs
OS:
windows_xp
Sub-Component:
java.awt
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Relates:
Relates:

Sub Tasks

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

--- 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);
!                 }
              }
          }
      }
                                     
2007-06-25
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.
                                     
2007-06-25
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.
                                     
2007-06-25



Hardware and Software, Engineered to Work Together