Skip to main content

Tiger and dates don't get along

Posted by mister__m on February 8, 2006 at 9:27 AM PST

Since Java WebStart 1.4 does not work on Linux kernel 2.6, there are many new features in a certain operating system release that are interesting to the customer I am currently working for and some applications they are willing to use require Java 5, we have started testing their main application on Tiger. However, it fails miserably due to two major bugs that have been available since the first day Java 5 was released.

First, TimeZone.setDefault(TimeZone) is severely broken. Instead of setting the JVM-wide TimeZone default instance, it now works on a thread-basis!. Ok, to be more precise, it uses a InheritableThreadLocal, which means you will have to set the TimeZone instance for all "parent" threads in your application. If you are developing a desktop application and setting the default TimeZone from the main thread before the GUI starts, all code that runs from the event dispatch thread won't see your changes! This bug has been reported and the submitter even suggested a workaround for the event dispatch thread, but the fix will only be available on Update 7!

Then, there is a binary compatibility bug since the first Java 5 release: java.sql.Timestamp.compareTo(java.util.Date) now throws a ClassCastException. If you declared all your references as Dates and used Hibernate, for instance, to initialize them, it is pretty hard to isolate these problems. It gets a lot worse if you have used Collections.sort(..) or Collections.max(..) in your code, since it gets impossible to detect this. This bug has been reported nearly one year and a half ago and has only been fixed last month. However, the fix will only be available in Update 7, whenever it is available.

So, if you deal with Date, Calendar or use Timestamp comparissons in your JDK 1.4 compatible system or even plan to do so in Tiger, hold your breath: wait for Update 7, whenever it comes around. If you have to upgrade to Java 5 by a certain date due to other reasons, you are in big trouble, just like me. Notice I didn't even mention all the daylight saving problems you will have to cope with if you are just interested in dealing with "plain" dates...

Unfortunately, the best advice I can give to anyone planning to do even some simple work with dates is to use Joda-Time, a great piece of Apache-licensed open-source software created by Stephen Colebourne.

As a JCP member, I have to ask: which companies or individuals is willing to support a JSR to add a Joda-Time based API to Dolphin and solve this mess in a proper manner?

Related Topics >>