Has jdk7u25 introduced a timezone error?

After 9 months of inactivity, I decided to update my software, including upgrading from jdk7u17 to u51. Some of my tests began to fail. Here is one of them:

public void testSimpleDateFormatDefaultTimeZone() throws ParseException {
    TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    long millis = sf.parse("1927-12-31 23:54:08").getTime()
        - sf.parse("1927-12-31 23:54:07").getTime();
    assertEquals(millis, 353000L);


    sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    millis = sf.parse("1927-12-31 23:54:08").getTime()
        - sf.parse("1927-12-31 23:54:07").getTime();
    assertEquals(millis, 353000L);


    sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    millis = sf.parse("1927-12-31 23:54:08").getTime()
        - sf.parse("1927-12-31 23:54:07").getTime();
    assertEquals(millis, 1000L);
}

It switches to u17 and fails on the first assertEquals, starting with u25. u21 is fine. Starting with u25, millis is calculated as 1000.

+4
source share
1 answer

As already mentioned in the comments, this is not an error, but an unconfirmed patch that was already deployed to jdk6 2 years ago.

0
source

Source: https://habr.com/ru/post/1526978/


All Articles