Adverts
I just wasted 20 minutes trying to figure out why a small portion of code wasn't giving me the result I expected and it turned out to be a really stupid mistake that without autoboxing and the JSP Expression Language would never have happened.
I was trying to default the style sheet for this site (notice how you can change it). I started off by loading a list of style sheets, to default the style sheet I was simply getting the head of the list with get( 0 ). This worked fine but I realized it would be simpler to load a map of style sheets keyed on the name which would allow me to look up the style sheet without having to iterate the list or query the database. In my haste to get the job done I simply changed the return type of the method that created the map (and of course made the other required changes to that method).
Now, pre-autoboxing, the get( 0 ) call that was used on the list would have thrown a wobbly if used on a Map because primitives couldn't be used as keys. The key for this map, however, was a String so what happened â yep the primitive was boxed and automatically converted to a String! This resulted in the default style sheet always being null. To make matters worse the bit of EL in the header page doesn't fail if the object you are querying for a parameter is null e.g. using ${style_sheet.fileName}. In fact, as long as style_sheet is null you can ask for any parameter you want.
Give me my 20 minutes back (and remove auto-boxing)!