FULL PRODUCT VERSION :
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Darwin x.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
For dates before 1970, the Timestamp code only uses the milliseconds to subtract a second. For times with 1,000,000 > nanos > 0 the times will be off by one second.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
// The current JDK has a bug where values of the form:
// YYYY-MM-DD HH:MM:SS.000X is off by a second for dates before 1970.
public static final boolean TIMESTAMP_BUG;
static {
Timestamp ts1 = Timestamp.valueOf("1969-12-25 12:34:56.0001");
Timestamp ts2 = Timestamp.valueOf("1969-12-25 12:34:56.0011");
// Compare the seconds, which should be the same.
TIMESTAMP_BUG = ts1.getTime()/1000 != ts2.getTime()/1000;
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
TIMESTAMP_BUG = false
ACTUAL -
TIMESTAMP_BUG = true
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.sql.Timestamp;
public class TimestampBug {
public static void main(String[] args) {
Timestamp ts1 = Timestamp.valueOf("1969-12-25 12:34:56.0001");
Timestamp ts2 = Timestamp.valueOf("1969-12-25 12:34:56.0011");
// Compare the seconds, which should be the same.
System.out.println("TIMESTAMP_BUG = " +
(ts1.getTime()/1000 != ts2.getTime()/1000));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Compensating code needs to detect whether the bug is there and add or subtract a second when 1,000,000 > nanos > 1.
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Darwin x.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
For dates before 1970, the Timestamp code only uses the milliseconds to subtract a second. For times with 1,000,000 > nanos > 0 the times will be off by one second.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
// The current JDK has a bug where values of the form:
// YYYY-MM-DD HH:MM:SS.000X is off by a second for dates before 1970.
public static final boolean TIMESTAMP_BUG;
static {
Timestamp ts1 = Timestamp.valueOf("1969-12-25 12:34:56.0001");
Timestamp ts2 = Timestamp.valueOf("1969-12-25 12:34:56.0011");
// Compare the seconds, which should be the same.
TIMESTAMP_BUG = ts1.getTime()/1000 != ts2.getTime()/1000;
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
TIMESTAMP_BUG = false
ACTUAL -
TIMESTAMP_BUG = true
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.sql.Timestamp;
public class TimestampBug {
public static void main(String[] args) {
Timestamp ts1 = Timestamp.valueOf("1969-12-25 12:34:56.0001");
Timestamp ts2 = Timestamp.valueOf("1969-12-25 12:34:56.0011");
// Compare the seconds, which should be the same.
System.out.println("TIMESTAMP_BUG = " +
(ts1.getTime()/1000 != ts2.getTime()/1000));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Compensating code needs to detect whether the bug is there and add or subtract a second when 1,000,000 > nanos > 1.