tags:

views:

44

answers:

2

Hello, It's 20:30 and I'm after a 6 hour bug hunt of an irritating bug caused by an uninitialized member variable.

In the our previous version we had the next few lines of code:

var aList = new Array;
for (var iDx=0; iDx < nNumOfElements; iDx++)
{
    // Some code
    aList.nCount = someValue;   //This line
}

aList.sort(function(a, b) { return b.nCount - a.nCount ; });

In the last release someone accidentally removed the line with comment. and there was no other initialization of the member variable nCount.

Some of our clients got a "Number expected" exception which is pretty obvious (in retrospect), strangely the error doesn't reproduce with our Q.A. nor 80% of our clients!

How can it be? is there any strict mode that we can run with that will find such pesky bugs? what is the difference between the clients that got the exception and ones that didn't (it's not browser version nor windows version)

(our system runs only on IE6+ in a special container which makes it hard for us to write the code in normal I.D.E.'s we pretty much write it all in notepad ++)

Thanks!

+6  A: 

You wrote int instead of var. I do that all the time...

int iDx=0 should be var iDx=0.

By the way, what editor are you using? int is a "future reserved word" in ES, so a good editor may highlight it in an ugly way (gedit makes it red with a red underline by default) to bring your attention to it.

no
haha, that has killed me so many times in JS
KennyCason
Curious, is this one cause of the JavaScript vs Java confusion? :P
BoltClock
I used a `bool` recently. :)
casablanca
Hmm... I think it's a typo in the question, otherwise the code would produce an *early* `SyntaxError`... anyway, good catch :)...
CMS
@Bolt it's probably as simple as JavaScript having the word Java in it, though, there are some syntactical similarities. :P
KennyCason
Oh Sh** sorry that was a mistake in the typing, in the real code it's var, thanks.
ManicQin
Ok, I edited the example, Like I said before my editor is notepad.Sorry if I explained it wrong - My problem was because I called the member nCount without initializing it - the question is why only 10% of our clients got an exception?I'm not a javascript programmer by trade so I'm kinda learning while I go.thank.
ManicQin
A: 

Looks like it's a bug with IE6 related to array sorting.

Try some of the workarounds suggested here...

no