JDK-5008227 : java.sql.Timestamp.after() is not returning correct result
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 5.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2004-03-04
  • Updated: 2004-03-30
  • Resolved: 2004-03-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b45Fixed
Related Reports
Relates :  
Relates :  
Description
/*
 * Running with jdk 1.4
 * Timestamp Value # 1  :  1970-01-02 00:00:00.999999999
 * Timestamp Value # 2  :  1970-01-02 00:00:00.001
 * after method returns true
 *
 * Running with jdk 1.5
 * Timestamp Value # 1  :  1970-01-02 00:00:00.999999999
 * Timestamp Value # 2  :  1970-01-02 00:00:00.001
 * after method does not return the expected Value Call to after is Failed!
 */
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.TimeZone;

public class TimestampBug {
  public static void main(String args[]) {
    int valToGeneralize = 0;

    Timestamp inTimeVal2 = null;
    String sLongTstampVal = null;
    String sNanosVal = null;
    boolean booRetVal;

    try {
      // setup
      TimeZone tz = null;
      tz = TimeZone.getDefault();
      boolean b1 = tz.useDaylightTime();
      if(!b1) {
        Calendar cal = Calendar.getInstance(tz);
        valToGeneralize =
tz.getOffset(cal.get(Calendar.ERA),cal.get(Calendar.YEAR),cal.get(Calendar.MONTH),cal.get(Calendar.DAY_OF_MONTH),cal.get(Calendar.DAY_OF_WEEK),cal.get(Calendar.MILLISECOND));
      }
      else {
        valToGeneralize = tz.getRawOffset();
      }
      // end setup

      //DateTime_Str_Val1=1970-01-02 00:00:00.001
      //DateTime_Long_Val1=86400001
      //Ref_Nano_Val = 999999999
      sLongTstampVal = "86400001";
      long tstampVal1 = Long.parseLong(sLongTstampVal);
      tstampVal1=tstampVal1-valToGeneralize;
    
      sNanosVal = "999999999";
      int nanosSet = Integer.parseInt(sNanosVal);
    
      Timestamp inTimeVal1= new Timestamp(tstampVal1);
      inTimeVal1.setNanos(nanosSet);
      System.out.println("Timestamp Value # 1  :  " + inTimeVal1);
    
      inTimeVal2= new Timestamp(tstampVal1);
      System.out.println("Timestamp Value # 2  :  " + inTimeVal2);
    
      booRetVal = inTimeVal1.after(inTimeVal2);
      if(booRetVal)
        System.out.println("after method returns " + booRetVal);
      else {
        System.out.println("after method does not return the expected Value
" + "Call to after is Failed!");
      }
    } catch(Exception e) {
      e.printStackTrace();
      System.out.println("Call to after is Failed!");
    }
  }
}

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-beta2 FIXED IN: tiger-beta2 INTEGRATED IN: tiger-b45 tiger-beta2
14-06-2004

EVALUATION This is a side effect caused by the 4340146 fix. Because Date.after() no longer calls getTime(), after() and equals() in Timestamp work compare different time values. Timestamp.after and before should call compareTo which works correctly. ###@###.### 2004-03-15
15-03-2004