Saturday, June 05, 2010

A 10-Year-Old Bug

Yesterday, as I was cataloging this week's comic purchases in my Java/SQL inventory application, I encountered a bug that has almost certainly been there since I wrote the app back in the late 90s. With it having remained unseen for so long, you might think it was date- or capacity-related, as those sorts of errors have reared their ugly heads over the past decade. But no, this was a straight up boo-boo: an SQL DELETE statement, constructed by stringing together the contents of variables and string constants, in which I neglected to surround a particular value with quotes (single apostrophes).

It was for the issue number of a comic, which in most cases is something like 24, 595 or ANN10 (for Annual # 10). For those types of values, the apostrophes are optional, it seems. But if you have something like "ANN 1", with an embedded space in it, then you need to enclose the string within the apostrophes or else you'll cause an error in your SQL command... which is exactly what happened. Fortunately, the application doesn't crash in such situations because I've put enough defensive and diagnostic code in place to handle the unexpected. Instead, I got an error message which was explicit enough to point me right to the faulty line of code, and 2 minutes later I'd fixed it, recompiled, and deleted the erroneous entry that I had originally wanted to.

But I was still amazed that the bug had lasted that long without ever being tripped. Just goes to show how software really is full of ticking time bombs.

1 comment:

Vicki said...

Seriously? You'd never entered Ann 1 before? But you have lots of those...hmmmmm