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

awt.Rectangle.inside(int,int) method doesn't check whether rectangle is empty

XMLWordPrintable

    • 2d
    • beta
    • sparc
    • solaris_2.6



      Name: acR10002 Date: 12/03/2000


      The javadoc for class java.awt.Rectangle says:

      -------------------------
      A Rectangle whose width or height is negative is considered empty.
      ...
      No point can be contained by or inside an empty Rectangle.
      -------------------------

      However, implementation can violate this rule under certain conditions.
      Please consider the following test:
      --------- Test.java ------------------
      import java.awt.Rectangle;

      public class Test {
          public static void main(String args[]) {
      Rectangle r = new Rectangle(-1,-1,-1,-1);
      if (r.inside(Integer.MAX_VALUE,Integer.MAX_VALUE)) {
      System.out.println("FAILURE: empty rectangle contains a point");
      } else {
      System.out.println("OKAY");
      }
          }
      }
      --------------------------------------
      An output will be (same for all JDK versions):

      --> java Test
      FAILURE: empty rectangle contains a point

      This happens because of overflow conditions are reached during calculations.
      To prevent this, regardless of an algorithm used to determine whether the point
      belongs to rectangle or not, inside() method should check first whether this
      rectangle is empty.

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

            flar Jim Graham
            aycsunw Ayc Ayc (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: