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

java.awt.Polygon.getBounds() behaves erroneously when Polygon has 0 points

XMLWordPrintable

    • 2d
    • sparc
    • solaris_2.5



      Name: saC57035 Date: 03/18/99


      java.awt.Polygon.getBounds() returns senseless values in case of
      Polygon.npoints=0 and in subsequent calls.

      Javadoc doesn't cover this case at all.

      Here is the test demonstrating the bug:

      -----------------qq.java------------------------
      import java.awt.*;
       
      public class qq {

         public static void main(String[] args) {
              Polygon p = new Polygon();
      for (i=0; i<5; i++){
      System.out.println("npoints=" + p.npoints + " rectangle=" +
      p.getBounds());
      p.addPoint(i,i);
      }

      }

      ---------Output from the test---------------------

      npoints=0 rectangle=java.awt.Rectangle[x=2147483647,y=2147483647,width=1,height=1]
      npoints=1 rectangle=java.awt.Rectangle[x=0,y=0,width=-2147483648,height=-2147483648]
      npoints=2 rectangle=java.awt.Rectangle[x=0,y=0,width=1,height=1]
      npoints=3 rectangle=java.awt.Rectangle[x=0,y=0,width=2,height=2]
      npoints=4 rectangle=java.awt.Rectangle[x=0,y=0,width=3,height=3]

      --------------------------------------------------

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

            flar Jim Graham
            savzan Stanislav Avzan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: