Enough time has been spent fixing bugs and getting basic things working. Hopefully, this site will help fix that.
I mostly work with Java and Eclipse, but do enough web stuff to beat my head against a wall every once in a while. This site will have tips, tutorials, bug workarounds, and anything else I can think of that people might find worthwhile.
I suppose I could start with the simplest and most embarrassing debugging problem I ever hit…
In Eclipse (and most interactive debuggers), you can set up expressions that are evaluated whenever the debugged process halts. Because these expressions are evaluated in the current thread context, they have full access to read (or write to) local variables. I happened to put a typo in one of these expressions, and did the ol’ “assign instead of compare” trick, evaluating “str = null” instead of “str == null”.
I didn’t really notice the bug, and didn’t end up needing to see whether str was null or not, so I went back to another view, hiding the debug expressions I had set (out of sight, out of mind, right?). It was about that time I started noticing a bizarre new bug… whenever I would hit a breakpoint, str would be null, even if the code I was stepping through didn’t do a thing with str! Fancy that!
Lesson 1: If there is weird behavior when debugging, check to see if expressions are being evaluated without you knowing.
Lesson 2: Use “null == str” instead of “str == null” to avoid assignment vs. compare bugs. (this actually doesn’t work in all languages… wait for a future post)

No comments
Comments feed for this article
Trackback link
http://www.code-fix.com/2007/02/26/here-we-go/trackback/