The smaller the error the bigger the bug

26 . April 2008
written by Clemens Lang at Apr 26th 2008, 12:05

Bug tracking in software development can be a pain - especially when there doesn’t seem to be any logic behind the bug.

So we had that navigation tree at work consisting out of two category levels, for simplicity let’s call them Level-1-Category and Level-2-Category. Level-1-Categories could contain other Level-1-Categories and Level-2-Categories, while Level-2-Categories could only contain Level-2-Categories. The navigation was built, caching was implemented, everything seemed fine from a logic viewpoint, however it behaved weird where it would sometimes display the Level-2-Categories in a particular Level-1-Category and sometimes not or in different order.
When we finally found the bug (after hours of debugging) the scales fell off our eyes:

<?php $cacheID = md5($level1Cat->id.$level2Cat->id); ?>

Now imagine what happened when you had a $level1Cat with ID 1 and a $level2Cat with ID 12, that would write it’s cache to md5(‘112’); - and trying to open a $level1Cat with ID 11 and a $level2Cat with ID 2 it would read the cache md5(‘112’);. Unfortunately these classes did have the same interface, so no errors were thrown.
Changing the code to
<?php $cacheID = md5($level1Cat->id.'-'.$level2Cat->id); ?>
resolved the bug and finally fired the closing time-event for us.