Java News from Thursday, July 22, 2004

You're never as smart as you think you are. For a long time I was in the habit of writing code like this:

try {
  write some data onto a ByteArrayOutputStream...
}
catch (IOException ex) {
  // ByteArrayOutputStreams don't throw exceptions
}

However a lot of the static code analysis tools I use complained abut the empty catch blocks, so I rewrote these blocks like this, just to make the analyzers shut up:

try {
  write some data onto a ByteArrayOutputStream...
}
catch (IOException ex) {
  throw new RuntimeException("Something is seriously broken", ex);
}

Wouldn't you know it? Yesterday my project started throwing runtime exceptions out of four of these blocks in places where I knew nothing could possibly go wrong. I'm still investigating, but it looks like this may reflect bugs in character conversion in some but not all virtual machines and some but not all character encodings, particularly in Java 1.2.2 and 1.3.1.


The Apache Jakarta Project has released Commons Codec 1.3, an open source Java class library providing common encoders and decoders including Base-64, hexBinary, Soundex, and Metaphone. New encoders in this release include binary strings and quoited printable.