October 26, 2006
Interregnum interrupted

They've shortened the interregnum - we'll be sprinting again from tomorrow. Which is a pain, 'cos I'm up to by neck in a real beauty of a bug. I'm getting a ClassCastException from one of our domain objects - but only if the back end is MySQL. Running against PostgreSQL or SQL Server, it's all fine. This is deep into the domain layer; we should have left all the database stuff far behind - and besides, we are using Hibernate, so our database engine specific code is zero.

Naturally we discovered this bug at the last minute, during the demo run-through. Our functional test box runs on SQL Server, and on my machine where it was developed I run PostgreSQL, so it all looked fine, but our demo server runs MySQL. Lucky Tulna did a demo run-through, or it would have fallen over in front of the BSDs...

Update: Got the bugger last night in the pub. It turns our that MySQL's timestamp has somewhat less resolution than the other database engines that we were using. This meant that our domain objects's compareTo() method was finding two timestamps equal, so it resorted to lower order keys - one of which was an ArrayList. Now, for some reason, ArrayLists don't implement Comparable, so when Commons Lang's CompareToBuilder tried to cast them into Comparables, we got our ClassCastException!

The fix was simple - write a little ComparableList class, sub-classing ArrayList, and use that instead. Sorted.

Posted to Java by Simon Brunning at October 26, 2006 03:04 PM
Post a comment

Email Address:



Remember info?