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

Incorrect java doc for Timestamp.compareTo(Date)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 6
    • core-libs
    • b120
    • x86
    • windows_xp
    • Not verified

      A DESCRIPTION OF THE PROBLEM :
      this is a code which works in java 1.5.0_12
      but NOT in java 1.5.0_04 (ClassCastException)
      public static void main(String[] args) {
      Date date = new Date();
      Date ts = new Timestamp(date.getTime());
      System.out.println(ts.compareTo(date));
      }
      This behaviour broke compatibility to 1.4 and you corrected this in 1.5.0_12, but you forgot to change the documentation:
      If the argument is not a Timestamp object, this method throws a ClassCastException object. (Timestamp objects are comparable only to other Timestamp objects.) this is not true anymore

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      just say that now it works with any Date
      ACTUAL -
      If the argument is not a Timestamp object, this method throws a ClassCastException object. (Timestamp objects are comparable only to other Timestamp objects.) this is not true anymore

      URL OF FAULTY DOCUMENTATION :

      http://java.sun.com/javase/6/docs/api/java/sql/Timestamp.html#compareTo(java.util.Date)

            lancea Lance Andersen
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: