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

java.awt.Point.equals() implementation does not match spec

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.3.1
    • 1.2.0
    • docs
    • ladybird
    • generic
    • generic



        Name: vi73552 Date: 05/18/99


        The class java.awt.Point states the following in its
        JavaDoc comments for the equals method:
        @return "true if the object to be compared is an instance of Point
        and has the same values; false otherwise."

        But the implementation can sometimes return true if
        the object being compared to is NOT an instance of Point,
        contrary to what the JavaDoc says.

        Example Code:
        import java.awt.*;
        import java.awt.geom.*;

        public class Test {
            public static void main(String[] args) {
                Point p1 = new Point(10,10);
                Point2D p2 = new Point2D.Double(10L,10L);
                
                System.out.println("p1 == p2 --> " + (p1 == p2));
                System.out.println("p1.getClass() --> " + p1.getClass());
                System.out.println("p2.getClass() --> " + p2.getClass());
                System.out.println("p2 instanceof Point --> " +
                        (p2 instanceof Point));
                System.out.println("p1.equals(p2) --> " + p1.equals(p2));
                System.out.println("p2.equals(p1) --> " + p2.equals(p1));
            }
        }

        ///////////

        Output:
        D:\temp>java Test
        p1 == p2 --> false
        p1.getClass() --> class java.awt.Point
        p2.getClass() --> class java.awt.geom.Point2D$Double
        p2 instanceof Point --> false
        p1.equals(p2) --> true
        p2.equals(p1) --> true

        //////////////////////

        D:\temp>java -version
        java version "1.2"
        HotSpot VM (1.0fcs, mixed mode, build E)

        D:\temp>java -fullversion
        java full version "JDK-1.2-V"
        (Review ID: 83182)
        ======================================================================

              jballsunw Jennifer Ball (Inactive)
              vasya Vassili Igouchkine (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: