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

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

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 18
    • client-libs
    • None
    • behavioral
    • low
    • Hide
      In normal usage NPEs will be thrown when the desktop icon needs to be accessed by the implementation so normal application usage should be no worse off. An application which for some reason creates a JInternalFrame, sets a null icon, but then does nothing with the JInternalFrame (ie does not show it) will now get this up-front exception.
      Show
      In normal usage NPEs will be thrown when the desktop icon needs to be accessed by the implementation so normal application usage should be no worse off. An application which for some reason creates a JInternalFrame, sets a null icon, but then does nothing with the JInternalFrame (ie does not show it) will now get this up-front exception.
    • Java API
    • SE

      Summary

      Specify that javax.swing.JInternalFrame.setDesktopIcon(JDesktopIcon) will throw NullPointerException when passed a null object reference for the parameter.

      Problem

      Method setDesktopIcon(JDesktopIcon) of the javax.swing.JInternalFrame class ia allowing null to be specified for JDesktopIcon object. This leads to random exceptions later on when getDesktopIcon.setVisible(), getDeskopIcon.getParent() etc are called since null is not supposed to be a valid value.

      Solution

      Update the implementation to throw NullPointerException if null is passed to setDesktopIcon() and document this as part of the specification. Further note that subclassers - which have direct access to the protected field holding the JDesktopIcon - should not set it to null.

      Specification

      Update public class javax.swing.JInternalFrame as follows :

          /**
            * Sets the <code>JDesktopIcon</code> associated with this
            * <code>JInternalFrame</code>.
            *
            * @param d the <code>JDesktopIcon</code> to display on the desktop
      +     * @throws NullPointerException if the {@code d} is {@code null}
            * @see #getDesktopIcon
            */
           public void setDesktopIcon(JDesktopIcon d);
      
          /**
          * The icon that is displayed when this internal frame is iconified.
      +   * Subclassers must ensure this is set to a non-null value
      +   * during construction and not subsequently set this to null.
           * @see #iconable
          */
         protected JDesktopIcon desktopIcon;

            psadhukhan Prasanta Sadhukhan
            jleesunw Jon Lee (Inactive)
            Alexander Zvegintsev, Philip Race
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: