Wednesday, August 3, 2011

Immortalized in the Commit Logs

My name is now logged forever in the commit comments of a pretty Awesome Project!

Have a look at the commit log for yourself (look for my name next to "NPE").

Here's how it happened: One quiet evening in June I was looking at some code diffs of that Awesome Project (don't ask why) and saw something that didn't look quite right. Keep in mind all I was viewing was the diff so I didn't see the full context of the code. Here's the snippet I noticed:
if (varTable == null) {
    if (DEBUG) System.out.println("resizing from " + varTable.length + " to " +  getMetaClass(). getRealClass(). getVariableTableSizeWithObjectId());
    // lots more code...
}
Do you see the NullPointerException? The code just checked if varTable was null, then proceeds to dereference it. That just can't be right. I double-checked it and then finally looked at the whole file. Then I saw it, the DEBUG flag is set to false way up at the top of the file. That's why the lurking NPE never causes a problem. So what's your opinion? Is it a real bug? The code will never get executed so it's not really a problem. Is a NullPointerException still a bug if it's located in a block of unreachable code?

In any case, I thought I should at least alert @Headius, the guy who wrote it. The fix went in the next commit and he put my name in the comments! If I ever see @Headius speak at a conference I'll see if he'll autograph the commit log.

1 comments:

  1. If code were carved into granite, then it would not be a bug. However, since code is encoded ('natch) in editable electronic and electromagnetic media, it can be changed.

    My point? If someone were to change the value of DEBUG or the code that sets the value of DEBUG in such a way that it is possible for DEBUG to become true, the the bug will manifest in the worst possible way.

    Basically, some seemingly innocuous change "way the hell over there" would make the code blow up here. Bad juju for everyone.

    ReplyDelete