Benad's Web Site

For all the nice things you can have in a nice Java debugger, for example NetBeans, I never expected this to happen.

At work I was stuck having to make my own class to read a little-endian binary file with unsigned integer values and other weird things (we all know there is no such thing as "unsigned int" in Java and that it's big-endian, right?). So I made a class which wrapped around java.io.InputStream and had a "getUInt()" function in the form "public long getUInt()" that reads and returns the next "UINT32" from the InputStream.

And weird things happened in the debugger. I have this kind of code:

long i;
while ((i = reader.getUInt()) > 0) { //... }

I stop the code using a breakpoint at the first line, put my mouse over "i" in the debugger, and it would say "12". Put my mouse over "reader", and it shows me the object reference information and so on. Place my mouse over "getUInt()" and it would say "8". Place my mouse again over it, it would now say "0". And so on... What?

Duh! Next time, call the function "readUInt()", otherwise NetBeans thinks it's a Java Bean accessor function which shouldn't change the state of the object, and happily calls the function over and over again even though your code is not supposed to be running...

Published on May 10, 2006 at 07:46 EDT

Older post: Memories of UML...

Newer post: Building NetBeans projects without NetBeans