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

SwingUtilities.calculateInnerArea() throws NPE

XMLWordPrintable

    • beta
    • sparc
    • solaris_2.6



      Name: ooR10001 Date: 03/06/2001


      SwingUtilities.calculateInnerArea(JComponent c, Rectangle r) method throws
      NullPointerException when passed JComponent is null. This behavior contradicts
      with current javadoc which says:

      ----------------------------
      public static Rectangle calculateInnerArea(JComponent c,
                                                 Rectangle r)

            Stores the position and size of the inner painting area of the specified
            component in r and returns r. The position and size specify the bounds
            of the component, adjusted so as not to include the border area (the
            insets). This method is useful for classes that implement painting code.
            Parameters:
                  c - the JComponent in question; if null, this method returns null
                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                  r - the Rectangle instance to be modified; may be null
      ----------------------------

      This is a test example which shows this bug:
      ---------------------
      import javax.swing.SwingUtilities;
      import java.awt.Rectangle;

      public class test {

          public static void main(String[] args) {
            Rectangle r = SwingUtilities.calculateInnerArea(null, new Rectangle());
          }

      }
      ---------------------


      Test's output:
      ------------------------
      Exception in thread "main" java.lang.NullPointerException
              at
      javax.swing.SwingUtilities.calculateInnerArea(SwingUtilities.java:1724)
              at test.main(test.java:7)
      -----------------------

      It needs to be fixed.

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

            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: