views:

223

answers:

1

Are there any gotchas in JDK 6 which did not exist in earlier versions? I am interested in finding out some surprising changes like the following one in the way Timestamp.valueOf() works.

Timestamp.valueOf(), when provided with a timestamp which contains a date or a month with a single digit. eg. 2009-9-20, 2009-9-3, 2009-12-4 etc., behaves differently in JDK 6 - it throws an IllegalArgumentException saying that the timestamp is not properly formatted. Whereas JDK 5 (and earlier versions) works just fine providing the proper values with '0' prefixed to those single digit numbers.

JDK 6 is just being more strict because the method does expect it's argument to be a String in JDBC timestamp escape format. However, this BREAKS code written in JDK 5.

Code like:

String s = "2009-9-1 00:00:00";
Timestamp t = Timestamp.valueOf(s);

However JDK 6 is fine with hours, minutes, seconds being single digits. I have figured out what's wrong by looking at the source code of Timestamp class in JDK 6. I found an array intDate[] which is initialized to {4,2,2} and the length of each item in the date is checked against this array.

Now why did the time part work fine even when there are single digits in them? Because the code that checks the length against an equivalent array intTime[] is commented out in source.

The Timestamp class in JDK 5 did not have any of these checks and work just fine with such inputs.

I do not find such oddities mentioned anywhere in the official site. Though I found one other person having the same problem. This problem is easily fixable and I am interested in finding out other such odd changes that had happened in JDK 6.

+7  A: 

Officially, this

EDIT

Additionally you can take a look at Sun's bug database.

This link shows items in Java of type bug with status accepted and the keywords "1.6 1.5"

I check a few of them and it looks like what you need.

OscarRyz
@Oscar: I have given an example where JDK 6 behaves in an unexpected manner. I have seen the list of incompatibilities in the official site before posting the question here, though I did not find it much useful.
Vijay Dev
Also of note was the Mustang Regression Challenge (I believe all the issues mentioned were fixed before the First Customer Ship). https://mustang.dev.java.net/regchal/
Tom Hawtin - tackline
@Vijay Dev: I didn't knew you've checked the list before posting ( you didn't mentioned that in the original question ) I don't know either if you have already look into the Sun's bug database. Here's the link http://bit.ly/3ZohZ5
OscarRyz
@Oscar: True, I did not mention that in the question. The bug database however looks like what I was looking for. Thanks! Will look into it.
Vijay Dev
@Oscar: http://bugs.sun.com/view_bug.do?bug_id=6763465 (mentioned by @Tom Hawtin in the comments to the question) in the bug database contains information about the behaviour of Timestamp.valueOf(). Thanks again!
Vijay Dev