Thursday, January 12, 2006

Back at Eclipse contributions again. This time it's about assertions.

This one started when I was coding along on my poker analysis program, which I do for fun. Somewhere along the way I decided to start using Java assertions, and sprinkled them throughout my code, checking input parameters, class state invariants, and all the good things assertions are supposed to check.

Then, one of my tests uncovered a bug, and in tracing through it I found that it should have triggered an assertion above where it blew up. After yelling at my code that it couldn't be doing what it was doing and why didn't it get a clue, I realized that assertions weren't enabled. I had made a tacit assumption that for testing (like when you're running JUnit) assertions would be enabled by default. Well, since they're obviously not, I searched in Eclipse help for how to enable assertions. Surprisingly, I found nothing. Then I yelled at the Eclipse help file and it didn't respond any more than my code had.

OK, so next stop on the hacker highway is google, so I searched for "enable assertions eclipse." When I first did this (which was last month - I am writing this a bit after the fact) it took a bit of digging, and most of the hits were people asking how in the name of the deity of their choice do you do this, and screaming in frustration. But a bit down the list, somebody mentions it's a VM argument, and you enable assertions by setting an "-ea" flag on the java virtual machine when you launch. Note if you do this same google search now, you get much better info, and the top 5 hits all tell you about the VM flag (including the long version "-enableassertions") right away.

OK - so thus enlightened I go to my favorite Eclipse launch configuration dialog, type in the magic "-ea" incantation, and voila, my code blows up with assertion errors all over the place and I lose a bunch of time fixing obscure bugs in old cold code I implemented months ago along with its never before activated assertions.

Allright, well, this will never happen again. I dilligently keep re-entering the "-ea" argument whenever it dissapears because I updated Eclipse or breathed on my computer wrong or whatever. It always seems to dissapear following simple rules that anyone should know but me, and then I forget and I'm no longer running with assertions and go through the evil cycle again.

So, after a few rounds of this, I decide this is enough of a pain in the rear that maybe I should try another Eclipse fix that allows you to check a check box somewhere and it remembers to enable assertions for you following rules a user who's not an Eclipse committer can understand.

Next - somebody's already entered the bug.

0 Comments:

Post a Comment

<< Home