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

5103041's fix does not comply with the spec.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 5.0u7
    • core-libs
    • b114
    • x86
    • windows_xp
    • Not verified

      With the fix pattern of 5103041, the implementation is not in line
      with API saying.

      http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Timestamp.html#compareTo(java.util.Date)
      ----->
      public int compareTo(Date o) Compares this Timestamp object to the
      given Date, which must be a Timestamp object. If the argument is not a
      Timestamp object, this method throws a ClassCastException
      object. (Timestamp objects are comparable only to other Timestamp
      objects.)
      <-----

      Below is 5103041's source diff. It never throw ClassCastException though
      specifying an object other than Timestamp in the argument.

      ----->
      ------- Timestamp.java -------
      *** /tmp/geta5365 Tue Apr 24 01:22:01 2007
      --- /tmp/getb5365 Tue Apr 24 01:22:01 2007
      ***************
      *** 1,5 ****
        /*
      ! * %W% %E%
         *
         * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
         * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
      --- 1,5 ----
        /*
      ! * @(#)Timestamp.java 1.58 04/05/18
         *
         * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
         * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
      ***************
      *** 464,482 ****
             * and a value greater than <code>0</code> if this
             * <code>Timestamp</code> object is after the given argument.
             *
      - * @exception ClassCastException if the argument is not a
      - * <code>Timestamp</code> object
             * @since 1.5
             */
      - // This forwarding method ensures that the compareTo(Date) method defined
      - // in java.util.Date is not invoked on a Timestamp
            public int compareTo(java.util.Date o) {
                return compareTo((Timestamp)o);
            }
                    
      -
      -
      -
            static final long serialVersionUID = 2745179027874758501L;
        
        }
      --- 464,485 ----
             * and a value greater than <code>0</code> if this
             * <code>Timestamp</code> object is after the given argument.
             *
             * @since 1.5
             */
            public int compareTo(java.util.Date o) {
      + if(o instanceof Timestamp) {
      + // When Timestamp instance compare it with a Timestamp
      + // Hence it is basically calling this.compareTo((Timestamp))o);
      + // Note typecasting is safe because o is instance of Timestamp
                   return compareTo((Timestamp)o);
      + } else {
      + // When Date doing a o.compareTo(this)
      + // will give wrong results.
      + Timestamp ts = new Timestamp(o.getTime());
      + return this.compareTo(ts);
              }
      + }
        
            static final long serialVersionUID = 2745179027874758501L;
        
        }
      <-----

            lancea Lance Andersen
            xiaojuzh Xiaojun Zhang (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: