Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6219532

NPE: setAlwaysOnTop on File and Print dialog

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 6
    • 6
    • client-libs
    • b24
    • generic
    • generic

      When setAlwaysOnTop is called on FileDialog or PrintDialog, it throws NPE from native code:

      Exception in thread "main" java.lang.NullPointerException: null pData
               at sun.awt.windows.WWindowPeer.setAlwaysOnTop(Native Method)
               at java.awt.Window.addNotify(Window.java:471)
               at java.awt.Dialog.addNotify(Dialog.java:376)
               at java.awt.FileDialog.addNotify(FileDialog.java:266)
               at java.awt.Dialog.conditionalShow(Dialog.java:441)
               at java.awt.Dialog.show(Dialog.java:506)
               at java.awt.Component.show(Component.java:1303)
               at java.awt.Component.setVisible(Component.java:1256)
               at Crash.main(Crash.java:16)

      This happens because these components (their peers) don't have a window associate with them all the time. The standard way to deal with this is to override the methods which may be called on these components and require such a window, to none.

      setAlwaysOnTop is now called from addNotify, so this affects the behavior of all these dialogs even if they were not explicitly been made always-on-top.

      Test to reproduce:

      import java.awt.*;
      public class Crash
      {
           public static void main(String[] args)
           {
               Frame f = new Frame("F");
               f.setBounds(100, 100, 200, 100);
               f.setVisible(true);

              FileDialog fd = new FileDialog(f);
              fd.setVisible(true);
           }
      }

      ###@###.### 2005-1-20 14:21:05 GMT

            dmikhalksunw Denis Mikhalkin (Inactive)
            dmikhalksunw Denis Mikhalkin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: