Insane Programming Java ramblings and finds on the net

14Oct/090

The danger of nested exceptions in Java Webstart applications

Everyone knows the following snippet:

try
{
   // snip
}
catch(SomeCheckedException ex)
{
   throw new RuntimeException("Hey, some exception occurred", ex)
}

It's your standard 'I hate checked exceptions, let's transform them into unchecked ones'. Sometimes, you won't even notice it happening. Using Spring and Hibernate, checked exceptions are a rare thing to encounter, since the framework nicely encapsulates them into unchecked ones. But there's a hidden danger lurking within these exceptions. See that second parameter in the exception? It's that one that can cause some problems when dealing with WebStart applications connecting to a remoted back-end somewhere.

21Sep/09Off

Look out: WeakHashMap

Reading the Javadocs is something people don't do very often. Programming has been a trial and error profession (which profession isn't?) and although test driven development has mitigated most of the error-part, creating bugs due to those little nuances in Javadocs which one might skip easily happens all to often.
As was the case today. We just got a bugreport for a OutOfMemoryError, which got traced back to a WeakHashMap that wasn't discarding its values on garbage collection. How could that be, one might ask? It's the reason of existing for a WeakHashMap: avoiding out of memory errors.