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

Unspecified javax.swing.JComponent.getInsets(null) behavior

XMLWordPrintable

    • beta2
    • sparc
    • solaris_2.6



      Name: ooR10001 Date: 10/27/2000


      It is unspecified whether NullPointerException should be thrown when passed-in object is null in
      method getInsets(java.awt.Insets) in javax.swing.JComponent class.

      The javadoc says:
      "The passed-in Insets object will be reused if possible.
      Calling methods cannot assume that the same object will be returned, however."

      It is possible to pass null object and expect that new Insets object will be returned.
      On the other hand, NullPointerException does not conflict with existing specification.

      In current implementation of this method there are two states of JComponent: in one of them
      getInsets() method call throws NullPointerException, but in another state the same call does not
      throw NullPointerException.

      The following test demonstrates the problem:
      -----------------------------------------------
      import javax.swing.JComponent;
      import javax.swing.border.EmptyBorder;
      import java.awt.Insets;
      import java.awt.Color;

      class JCStub extends JComponent {

        public JCStub() {
            super();
        }

      };

      public class t {

        public static void main(String[] args) {
            JComponent c = new JCStub();
            c.setBorder(new javax.swing.plaf.basic.BasicBorders.SplitPaneBorder(
                            new Color(0,0,0), new Color(1,1,1)));
            try {
                Insets i = c.getInsets(null);
            } catch (NullPointerException e) {
                System.out.println("NPE thrown at first getInsets() call: " + e);
            }
            c.setBorder(new EmptyBorder(new Insets(1, 2, 3, 4)));
            try {
                Insets i = c.getInsets(null);
            } catch (NullPointerException e) {
                System.out.println("NPE thrown at second getInsets() call: " + e);
            }
        }

      }
      -------------------------------------------------
      Test's results (output):
      ---------------------------------
      NPE thrown at second getInsets() call: java.lang.NullPointerException
      ---------------------------------

      The doc needs to specify getInsets behavior when null parameter is passed and
      then implementation should be corrected according to new doc.

      ======================================================================

            svioletsunw Scott Violet (Inactive)
            oovsunw Oov Oov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: