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

java.awt.Window dimensions of zero causes Xt error and won't displau window

XMLWordPrintable

    • 1.1.6
    • sparc
    • solaris_2.6
    • Verified

        Using JDK on Solaris, if you create a java.awt.Window
        you can get a NPE and the window fails to be displayed
        unless you explicitly reshape the window before displaying it, to
        give it non-zero dimensions.

        This was observed with JDK1.1.4 on Solaris 2.6, but is not limited to
        that combination.

        You get no clue what happened under java - just no window appears

        Running under java_g you would see the following

        % java_g ShowWindow
        Xt error
        Exception occurred during event dispatching:
        java.lang.NullPointerException
                at sun.awt.motif.MComponentPeer.<init>(MComponentPeer.java:106)
                at sun.awt.motif.MCanvasPeer.<init>(MCanvasPeer.java:35)
                at sun.awt.motif.MPanelPeer.<init>(MPanelPeer.java:29)
                at sun.awt.motif.MWindowPeer.<init>(MWindowPeer.java:42)
                at sun.awt.motif.MToolkit.createWindow(MToolkit.java:140)
                at java.awt.Window.addNotify(Window.java:106)
                at java.awt.Window.pack(Window.java:122)
                at ShowWindow.actionPerformed(ShowWindow.java:28)
                at java.awt.Button.processActionEvent(Button.java:254)
                at java.awt.Button.processEvent(Button.java:227)
                at java.awt.Component.dispatchEventImpl(Component.java:1764)
                at java.awt.Component.dispatchEvent(Component.java:1704)
                at java.awt.EventDispatchThread.run(EventDispatchThread.java:63)

        At a Java application code level we
        1) create a window
        2) add a child component
        3) display the window

        Internally when we do the last step, the AWT creates peer objects
        and the Motif pop up shell via "XtCreatePopupShell"

        When this happens Xt generates an error, since the child component
        has not been used to define an initial size for the window , and
        so the values passed in are both zero.

        Xt explicitly barfs at this, generating an Xt error.

        In libXt/Intrinsic.h, the Realize() method has a check:

                if (wid->core.width == 0 || wid->core.height == 0) {
                    Cardinal count = 1;
                    XtErrorMsg("invalidDimension", "shellRealize", XtCXtToolkitError,
                               "Shell widget %s has zero width and/or height",
                               &wid->core.name, &count);
                }

        JDK's installed xtError() handler emits the concise "Xt Error" message
        if running under java_g. The default Xt error concerning invalid
        dimensions would have been more clear.

        The problem occurs in src/solaris/sun/awt_Window.c

        java test case herewith
        // ShowWindow.java

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

        class ShowWindow extends Frame implements ActionListener, WindowListener {

          public static void main(String args[]) {
            ShowWindow w = new ShowWindow();
            w.setVisible(true);
          }

          public ShowWindow() {
            super("ShowWindow");
            setLayout(new FlowLayout());
            add(showButton = new Button("Show"));
            add(hideButton = new Button("Hide"));
            showButton.addActionListener(this);
            hideButton.addActionListener(this);

            win = new Window(this);
            win.add("Center", new Label("Hello World"));
            addWindowListener(this);
            pack();
          }

          public void actionPerformed(ActionEvent e) {
            if (e.getSource() == showButton) {
                //win.reshape(400,200,100,100);
                win.pack();
                win.setVisible(true);
            }
            else if (e.getSource() == hideButton)
                win.setVisible(false);
         }
         

         public void windowOpened(WindowEvent e) {
         }

         public void windowClosing(WindowEvent e) {
           System.exit(0);
         }

         public void windowClosed(WindowEvent e) {
         }

         public void windowIconified(WindowEvent e) {
         }

         public void windowDeiconified(WindowEvent e) {
         }

         public void windowActivated(WindowEvent e) {
         }

         public void windowDeactivated(WindowEvent e) {
         }


         private Window win;
         private Button showButton;
         private Button hideButton;

        }

              bklocksunw Brian Klock (Inactive)
              prr Philip Race
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: