Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netbeans Java Debugger claims that ((true && false) == true)

I just encountered something that defies my understanding of logic. How can the situation below occur?

enter image description here

I've tried all the usual approaches to remedy this; clean/build, restart netbeans, etc. but the problem persists. Variable complete is always true, no matter what I do. I even replaced left and right with true and false boolean values respectively, but no change. What did work, was a refactor rename of the variable, but when I changed it back to the original, the problem resurfaced. There are no class members named the same way.

What's going on? Have I finally lost my mind, or should that variable have a value of false?

This is with Netbeans 7.3.1 on Windows.

Edit01

I'll try to prove it to the unbelievers that this is actually happening, when I get access to my work computer in a week or so. In the mean while, just take my word for it. THIS IS NOT A PRANK nor did it happen due to my lack of knowledge of debugging with Netbeans.

I do remember doing a bunch of svn switch-to-copy commands before this occurred, but not for the project where this code resides in (dependencies). A clean/build should have taken care of any inconsistencies anyways. I also did not remember to clear the Netbeans cache, which I now regret.

Edit02

Haters gonna hate, but as I feared, after returning to my workstation, I can no longer reproduce this issue. It pisses me off to admit this, but I have no proof whatsoever that this had ever happened. All I did was: woke up my pc from hibernation, undid a refactor rename of my variable, which was the last thing I had done before finishing my work, a clean/build and then another debug run. Everything just..works.

like image 304
predi Avatar asked Dec 23 '13 14:12

predi


People also ask

Does NetBeans have debugger?

NetBeans IDE provides a debugging toolbar that helps you step through your files. See Working with the Toolbar and Editor.

How do I remove all Debug points in NetBeans?

To delete breakpoints go to Window-> Debugger and select "Delete All".


1 Answers

I see a couple of possibilities, but I don't believe it is internally wrong in the JVM. The debugger is probably simply tricked or bugged.

  1. Some optimization is going on under the hood that causes left and complete be the same variable on the stack. So this would roughly means that your code got optimized to this:

    boolean left = (start <= offset);
    boolean right = (stop + 1 >= offset);
    left = left && right;   // reused "left" instead of new variable "complete"
    

    However, as far as I know, Java compilers don't do this sort of optimization. Can someone confirm or give details if this is not true? (Maybe javac or the JIT does this?)

  2. NetBeans debugger is really bugging. From my C++ debugging experience, there actually existed a bug in a debugger (sounds funny, right) that causes the debugger to be unable to read integer values from memory correctly. Sometimes the results were off. This doesn't mean anything in this case, but it actually is possible that debuggers do have bugs.

    I remember I've been searching for hours to fix a bug in my code I discovered by debugging. But there was no bug. At least not in my code. The debugger reported me some values in memory, but were wrong.

If this weird behavior happens always, then try to put a debug statement behind it:

System.out.println(left + " && " +  right + " == " + complete);

I bet the output will be correct. Try to run the debugger also with this line added. If such an optimization happens as I described, it should be gone, because it can't reuse left anymore.

like image 93
Martijn Courteaux Avatar answered Sep 22 '22 00:09

Martijn Courteaux