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

NPE may be thrown if JDesktopIcon is set to null on a JInternalFrame

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b12
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      Name: jl125535 Date: 03/17/2004


      FULL PRODUCT VERSION :
      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
      Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b42)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b42, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP 5.1.2600

      A DESCRIPTION OF THE PROBLEM :
      The constructor of JInternalFrame invokes setVisible(false), which triggers events on the AWT event queue. If JInternalFrame.getDesktopPane is invoked in response to this event, a NullPointer exception will be thrown.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See attached code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No exception should be thrown. It is arguably bad practice to put such side-effect-producing calls in the constructor (cf setText in JTextComponent).

      ACTUAL -
      java.lang.NullPointerException
              at javax.swing.JInternalFrame.getDesktopPane(JInternalFrame.java:1226)
              at JInternalFrameBug$Listener.eventDispatched(JInternalFrameBug.java:13)

              at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Toolkit.ja
      va:2136)
              at java.awt.Toolkit.notifyAWTEventListeners(Toolkit.java:1988)
              at java.awt.Component.dispatchEventImpl(Component.java:3530)
              at java.awt.Container.dispatchEventImpl(Container.java:1627)
              at java.awt.Component.dispatchEvent(Component.java:3477)
              at java.awt.Container.addImpl(Container.java:675)
              at javax.swing.JInternalFrame.addImpl(JInternalFrame.java:446)
              at java.awt.Container.add(Container.java:518)
              at javax.swing.JInternalFrame.setRootPane(JInternalFrame.java:672)
              at javax.swing.JInternalFrame.<init>(JInternalFrame.java:273)
              at javax.swing.JInternalFrame.<init>(JInternalFrame.java:203)
              at JInternalFrameBug.main(JInternalFrameBug.java:25)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      /** Demonstrates NPE when creating a JInternalFrame */
      public class JInternalFrameBug {

          private static class Listener implements AWTEventListener {
              public void eventDispatched(AWTEvent e) {
                  if (e.getSource() instanceof JInternalFrame) {
                      try {
                          JInternalFrame f = (JInternalFrame)e.getSource();
                          JDesktopPane df = f.getDesktopPane();
                      }
                      catch(NullPointerException npe) {
                          npe.printStackTrace();
                          System.exit(1);
                      }
                  }
              }
          }

          public static void main(String[] args) {
              Toolkit.getDefaultToolkit().addAWTEventListener(new Listener(), -1);
              JInternalFrame f = new JInternalFrame();
              while (true)
                  ;
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Catch the NPE when invoking JInternalFrame.getDesktopPane, or reimplement the function and check for a null pointer.
      (Incident Review ID: 240158)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              psadhukhan Prasanta Sadhukhan
              Reporter:
              jleesunw Jon Lee (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: