Intellij调试器在foreach循环中找不到本地变量

发布于 2025-01-23 12:33:08 字数 1325 浏览 0 评论 0原文

尝试调试以下块时,我会遇到Intellij的错误:

1.  private boolean compareMatrices(Map<String, Map<String, Double> toCompare) {
2.      for (String c1 : this.keySet()) {
3.          Map<String, Double> thisRow = this.get(c1);
4.          Map<String, Double> otherRow = toCompare.get(c1);
5.
6.          for (Entry<String, Double> cell : thisRow.entrySet())
7.              if (!otherRow.get(cell.getKey()).equals(cell.getValue()))
8.                  return false;
9.      }
10.     return true;
11. }

我已经在第7行上放置了一个条件etherrow.get(cell.getKey())== null并获取“每当点击点击点时,调试器无法找到本地变量单元格”错误。如果我将For Block(第6-8行)包装在牙套中,则不会发生此错误,因此:

1.  private boolean compareMatrices(Map<String, Map<String, Double> toCompare) {
2.      for (Stringc1 : this.keySet()) {
3.          Map<String, Double> thisRow = this.get(c1);
4.          Map<String, Double> otherRow = toCompare.get(c1);
5.
6.          for (Entry<String, Double> cell : thisRow.entrySet()) {
7.              if (!otherRow.get(cell.getKey()).equals(cell.getValue()))
8.                  return false;
10.         }
10.     }
11.     return true;
12. }

我的问题是,我可能犯了一个配置错误,还是这确实是与Intellij的误解有关的错误Java语法?另外,有条件的断点是否会大大减慢调试器?使用上面的第二版时,调试器执行正确,但要比正常执行时间长10倍。

I'm getting an error with IntelliJ when attempting to debug the following block:

1.  private boolean compareMatrices(Map<String, Map<String, Double> toCompare) {
2.      for (String c1 : this.keySet()) {
3.          Map<String, Double> thisRow = this.get(c1);
4.          Map<String, Double> otherRow = toCompare.get(c1);
5.
6.          for (Entry<String, Double> cell : thisRow.entrySet())
7.              if (!otherRow.get(cell.getKey()).equals(cell.getValue()))
8.                  return false;
9.      }
10.     return true;
11. }

I have placed a breakpoint on Line 7 with the condition otherRow.get(cell.getKey()) == null and get the "Cannot find local variable cell" error from the debugger whenever the breakpoint is hit. That error does not happen if I enclose the for block (Lines 6-8) in braces, like this:

1.  private boolean compareMatrices(Map<String, Map<String, Double> toCompare) {
2.      for (Stringc1 : this.keySet()) {
3.          Map<String, Double> thisRow = this.get(c1);
4.          Map<String, Double> otherRow = toCompare.get(c1);
5.
6.          for (Entry<String, Double> cell : thisRow.entrySet()) {
7.              if (!otherRow.get(cell.getKey()).equals(cell.getValue()))
8.                  return false;
10.         }
10.     }
11.     return true;
12. }

My question is, is the error coming from a configuration mistake I may have made, or is this really a bug relating to IntelliJ's misinterpretation of Java syntax? Also, do conditional breakpoints significantly slow down the debugger? When using the second version above, the debugger executes correctly, but takes over ten times longer than in normal execution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奶气 2025-01-30 12:33:08

您的代码是有效的Java,因此它不能是配置错误。我怀疑这是一个Intellij错误。我的猜测是您:

  • 用存在的括号编译了程序

  • 以调试模式运行程序

  • 删除括号

  • 删除了用断点

    执行的括号

,现在您的源代码与编译后的代码不匹配,因此错误。

停止执行,再次使用代码的第一个版本构建项目,然后尝试再次调试。


另外,有条件的断点会大大减慢调试器吗?

是的,有可能。场和方法断点也比“常规”的断点明显慢。

Your code is valid java thus it cannot be a configuration mistake. I doubt that it's an IntelliJ bug. My guess is that you:

  • compiled the programm with the brackets present

  • run the program in debug mode

  • removed the brackets

  • executed the line with the breakpoint

and now your source code doesn't match the compiled one, hence the error.

Stop the execution, build your project again with the first version of the code and try debugging it again.


Also, do conditional breakpoints significantly slow down the debugger?

Yes, it's possible. Field and method breakpoints are also significantly slower than "regular" ones.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文