简体   繁体   English

Netbeans Java Debugger声称((true && false)== true)

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

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. 清理/构建,重新启动netbeans等,但问题仍然存在。 Variable complete is always true, no matter what I do. 可变complete始终是真实的,不管我做什么。 I even replaced left and right with true and false boolean values respectively, but no change. 我甚至分别用truefalse布尔值替换了leftright ,但没有改变。 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 ? 我最终失去了理智,或者该变量的值是否为false

This is with Netbeans 7.3.1 on Windows. 这是Windows上的Netbeans 7.3.1。

Edit01 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. 这不是一个恶作剧,也不是因为我缺乏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). 我确实记得在发生这种情况之前做了一堆svn switch-to-copy命令,但不是这个代码所在的项目(依赖项)。 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. 我也不记得清除Netbeans缓存,我现在后悔了。

Edit02 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. 我看到了几种可能性,但我不相信它在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. 在引擎盖下进行了一些优化,导致leftcomplete在堆栈上是相同的变量。 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. 但是,据我所知,Java编译器不会进行这种优化。 Can someone confirm or give details if this is not true? 如果不是这样,有人可以确认或提供详细信息吗? (Maybe javac or the JIT does this?) (也许javac或JIT这样做?)

  2. NetBeans debugger is really bugging. NetBeans调试器真的很烦人。 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. 从我的C ++调试经验来看,实际上调试器中存在一个错误(听起来很有趣,正确)会导致调试器无法正确读取内存中的整数值。 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. 如果这样的优化情况,因为我所描述的,应该消失,因为它不能重用left了。

我复制了你的代码,这是我发现的:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM