skip to content

Java inconsistencies strike again

April 10, 2006

Don’t get me wrong, I really like the Java programming language. But sometimes it has these weird inconsistencies that just drive you crazy.

Like this morning, my co-worker was struggling with a HashMap where it wasn’t returning the value he expected. He was printing it out in a JSP but kept getting a blank instead of the string that the code was setting earlier. We walked thru his code and I saw the bug instantly–a simple spelling error in the name of the value he was trying to retrieve.

Stuff like that drives me crazy. Why are there collections like Arrays where you’ll get an exception if you try to retrieve something outside the boundaries, but HashMap will quietly return a null object when you try to retrieve an undefined variable? That’s just wildly inconsistent behavior, and I’ve seen it bite so many people.

It was an especially big problem at CNET, because a lot of the pages are built around the architecture where a controller loads up up all kinds of values from the database into the environment and then forwards to a JSP, where you then pull the values back out by name from a HashMap-like data structure.

Accidentally spell a value wrong and suddenly part of your JSP page fails to render. But you don’t get any useful debugging or exception info, just a blank space. Early on it was actually easier because we had configured the JSP engine to spit out the word “null” whenever it attempted to print a null object. For some reason we decided to change that default behavior, I can’t remember why. So now it just spits out nothing whenever printing a null object.

You waste so much time tracking down bugs like this. Smart IDE’s help some, but most of them can’t catch these kinds of run-time issues. You just have to debug ‘em when they come up.

Comments RSS

  1. sMoRTy71

    “You just have to debug ‘em when they come up.”

    Or learn to spell :)

TrackBack URI

Leave a comment