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

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

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.4.0
    • Fix Version/s: 1.4.0
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
      2d
    • Resolved In Build:
      beta
    • CPU:
      sparc
    • OS:
      solaris_2.6

      Description



      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.

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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: