4

After 9 months of inactivity I chose to update my software including updating from jdk7u17 to u51. Some of my tests started to fail. Here is one:

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 passes on u17 and fails at the first assertEquals starting with u25. u21 is ok. From u25 onwards, millis is calculated to be 1000.

user1050755
  • 11,218
  • 4
  • 45
  • 56
  • 1
    Have a look at this question: http://stackoverflow.com/questions/6841333/why-is-subtracting-these-two-times-in-1927-giving-a-strange-result?rq=1 – sheltem Feb 14 '14 at 16:14
  • 2
    well, that question actually lead me to create that test. :-) the bug is that the reason for that question obviously disappeared with u25...?? – user1050755 Feb 14 '14 at 16:21
  • 1
    The difference may be explained by 1927-12-31 23:54:08 happening *twice* in Shanghai. Maybe the choice which one it parses to was changed from one version to another? If it chooses the first instance, the time difference is one second (1000 ms), if it chooses the other, it's 353 seconds. – sheltem Feb 14 '14 at 16:22
  • 1
    http://www.oracle.com/technetwork/java/javase/tzdata-versions-138805.html <- This is a list of timezone data versions in the various jre versions. There was a change in 7u25, so even though this specific sitation isn't explicitly mentioned, I'm rather confident that's the source. ;) You could dig through the different versions of the [IANA Time Zone Database](http://www.iana.org/time-zones) used to identify the change and where it occurred. – sheltem Feb 14 '14 at 16:35
  • 1
    submitted as bug to oracle. – user1050755 Feb 14 '14 at 19:53
  • 1
    actually, I now think they silently fixed it in 7u25. The behaviour was obviously considered a bug by Oracie. http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7070044 Fixed it 2 years earlier in jdk6. – user1050755 Feb 14 '14 at 21:04

1 Answers1

0

As already indicated in the comments, this is not a bug, but an unreported bugfix that had already been deployed to jdk6 2 years ago.

user1050755
  • 11,218
  • 4
  • 45
  • 56