Netbeans Java Debugger声称((true&& false)== true) [英] Netbeans Java Debugger claims that ((true && false) == true)

查看:144
本文介绍了Netbeans Java Debugger声称((true&& false)== true)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚遇到了一些不符合逻辑理解的东西。如何发生以下情况?





我已经尝试了所有通常的方法来弥补这一点;清理/构建,重新启动netbeans等,但问题仍然存在。变量完成始终是真实的,无论我做什么。我甚至用 true 和<$ code>替换 c $ c> false 布尔值分别,但没有变化。什么工作,是变量的重构名称,但是当我把它改回原来的时候,这个问题就重现了。没有类别的成员命名为相同的方式。



发生了什么事?我终于失去了思想,或者应该该变量的值为 false



这是与Netbeans 7.3 .1在Windows上



Edit01



我会尝试向不信的人证明这一点实际上正在发生,当我在一个星期内访问我的工作电脑。在平均而言,只是我的话。这不是一个PRANK,也没有发生,因为我缺乏对Netbeans的调试知识。



我记得做一堆svn切换到复制命令之前这是发生的,但不适用于此代码所在的项目(依赖关系)。干净/建设应该照顾任何不一致之处。我也不记得清除Netbeans缓存,我现在后悔。



Edit02



Haters会讨厌,但是我担心,我的工作站,我不能再重现这个问题。这让我感到难以承认,但是我并没有证明这是发生过的。我所做的就是:从休眠状态唤醒我的电脑,取消了我的变量的重构重命名,这是我完成工作之前完成的最后一件事,一个干净的/构建,然后是另一个调试运行。一切只是...工作。

解决方案

我看到几种可能性,但我不相信内部错误JVM。调试器可能只是被欺骗或者被窃取。


  1. 某些优化正在引发下,导致剩下完成是堆栈上的相同变量。所以这大概意味着你的代码被优化为:

      boolean left =(start< = offset); 
    boolean right =(stop + 1> = offset);
    left = left& amp;&对; //重用左而不是新变量完成

    然而,据我所知, Java编译器不做这种优化。如果这不正确,有人可以确认或给出详细信息吗? (可能javac或JIT这样做?)


  2. NetBeans调试器真的是bug。从我的C ++调试经验来看,调试器实际上存在一个错误(听起来很有趣,正确),导致调试器无法正确读取内存中的整数值。有时结果是关闭的。这并不意味着任何事情在这种情况下,但它实际上是可能的调试器确实有错误。



    我记得我一直在寻找几个小时修复一个错误我的代码我通过调试发现。但是没有bug。至少不在我的代码。调试器在内存中报告了一些值,但是错误。


如果这种奇怪的行为总是发生,那么尝试在其后面加上一个调试声明:

  System.out.println(left +&&+ right += =+完成) 

我知道输出将是正确的。尝试运行调试器也添加了这一行。如果这样的优化发生在我所描述的情况下,它应该已经不见了,因为它不能再次使用 left


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

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.

解决方案

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.

这篇关于Netbeans Java Debugger声称((true&amp;&amp; false)== true)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆