JDK-6469731 : Windows: getLocationOnScreen throws NPE for a page dialog
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6,7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp,windows_7
  • CPU: x86
  • Submitted: 2006-09-12
  • Updated: 2011-07-01
  • Resolved: 2011-07-01
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-poolResolved
Related Reports
Duplicate :  
Duplicate :  
Description
I've an AWTEventListener added using which I get the window instance of a PageDialog. Calling getLocationOnScreen on that window instance throws the following exception:

Exception in thread "Thread-2" java.lang.NullPointerException: null pData
        at sun.awt.windows.WComponentPeer.getLocationOnScreen(Native Method)
        at java.awt.Component.getLocationOnScreen_NoTreeLock(Component.java:1674)
        at java.awt.Component.getLocationOnScreen(Component.java:1652)

This is reproducible only on windows, from 5.0 onwards. Runs fine on solaris/linux.

To reproduce:
Run the below testcase.
Click the button labeled 'Click me' and wait till the page dialog appears. See the command window for the output of the getLocationOnScreen call. If an exception is thrown, bug is reproduced.

import java.awt.*;
import java.awt.print.*;
import java.awt.event.*;

public class GetLocationOnScreenTest implements AWTEventListener {
    
    private static Window w;
    private static boolean windowAppeared = false;
    
    public void eventDispatched(AWTEvent event) {
        if (event.getID() == WindowEvent.WINDOW_OPENED) {
            w = (Window) event.getSource();
            windowAppeared = true;
        }
    }
    
    public static void main(String[] args) {
        Toolkit.getDefaultToolkit().addAWTEventListener(
            new GetLocationOnScreenTest(), AWTEvent.WINDOW_EVENT_MASK);
        Frame f = new Frame();
        f.setLayout(new FlowLayout());
        f.setSize(200, 200);
        Button b = new Button("Click me");
        b.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                windowAppeared = false;
                new Thread(new Runnable() {
                    public void run() {
                        System.out.println("Sleeping");
                        try { Thread.sleep(5000); } catch (Exception e) {}
                        if (windowAppeared) {
                            System.out.println("Location: " + w.getLocationOnScreen());
                        } else {
                            System.out.println("Page dialog did not appear");
                        }
                    }
                }).start();
                PrinterJob.getPrinterJob().pageDialog(new PageFormat());
            }
        });
        f.add(b);
        f.setVisible(true);
    }
}

Comments
EVALUATION In current implementation file, print and page dialogs don't have any native objects associated with them. This native object (pointer to it) is stored at pData field in WComponentPeer, and trying to access it for native dialogs causes the NPE. This will be probably fixed with RFE 6179142.
13-09-2006