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

java.awt.Point.setLocation(double, double) works incorrectly

XMLWordPrintable

    • 2d
    • beta2
    • sparc
    • solaris_2.6



      Name: dsR10051 Date: 08/06/2001


      The method of class java.awt.Point
      public void setLocation(double x, double y)
      works incorrectly. The fixed javadoc spec (see #4221956:
      "java.awt.Point.setLocation(double, double) specs is not clear")
      says:
          /**
           * Sets the location of this point to the specified float coordinates.
           * The float values will be rounded to integer values.
           * Any number smaller than <code>Integer.MIN_VALUE</code>
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           * will be reset to <code>MIN_VALUE</code>, and any number
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           * larger than <code>Integer.MAX_VALUE</code> will be
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           * reset to <code>MAX_VALUE</code>.
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           *
           * @param x the <i>x</i> coordinate of the new location
           * @param y the <i>y</i> coordinate of the new location
           * @see #getLocation
           * @see java.lang.Math#round(float)
           */
          public void setLocation(double x, double y) {

      But the implementation ignores the marked rule.

      Here is minimized test:

      import java.awt.*;

      public class PointTest01 {

          public static void main (String[] args) {

              Point p = new Point();
              double x = Double.MAX_VALUE;
              double y = 0.0d;
              p.setLocation(x, y);
              System.out.println(p);
              if (p.x == Integer.MAX_VALUE) {
                  System.out.println("OKAY");
              } else {
                  System.out.println("FAILED");
              }
          }
      }

      --- Output ---
      %/set/jdk-builds/JDK1.4.0beta-b74/solaris/bin/java PointTest01
      java.awt.Point[x=-1,y=0]
      FAILED
      --------------

      The method behavior or javadoc spec should be updated.

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

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: