Symptoms: a change of behaviour of our code depending on whether in release or debug mode.
This is sometimes referred to as 'Heisenbug', taking its name from quantum physics Heisenberg uncertainty principle.
Someone prefers to call it "the active observer bug", and this is maybe a more appropriate definition. What usually happens is that our debugging code simply interferes with the program. This happens if our debugging code alters the value of some variables, stack objects or pointers. A typical case, for example in Java, is calling the nextItem() method of an Iterator inside a snippet of debugging code to access the correspondig object. This will shift the iterator pointer to its next position, thus altering the flux of the program. The solution in this case is obviously to assign the result of the nextItem() call to an object outside the debugging code, and "observe" this object. Analogous cases are pushing or popping to/from a stack object, and so on. Less frequently it happens that even calling an apparently "innocuous" method on an object, notifications could be sent to listeners, again potentially causing the bug.
Though it may not seem, active observer bugs are much more frequent than one can expect, as we usually don't "debug our debugging code".
The golden rule is to double check that our debugging code is really "neutral" and behaves just like a passive observer and, if possible, always observe primitive data types.
Mauro is a professional developer, platform integration evangelist, free information supporter and owner/webmaster of beanizer.org. When not developing software, he composes music, mainly for the theatre. |
No comments:
Post a Comment