调试器无法在Lambda中看到局部变量 [英] Debugger cannot see local variable in a Lambda
问题描述
我注意到当我的调试器在lambda内停止时将鼠标悬停在局部变量上时,它将报告找不到局部变量'variable_name'
即使它是可见的在lambda中使用它。
I noticed that when I hover my mouse over a local variable when my debugger is stopped inside a lambda it will report Cannot find local variable 'variable_name'
even if it's visible inside the lambda and it's used.
示例代码
public class Main {
public static void main(String[] args) {
String a = "hello_world";
m1(a);
}
private static void m1(String a) {
AccessController.doPrivileged((PrivilegedAction<String>) () -> {
System.out.println("blala " + a);
return "abc";
});
}
}
尝试使用中的断点System.out.println(blala+ a);
并在之后返回abc
并且它总是报告相同的错误。
Try with a breakpoint in System.out.println("blala " + a);
and after return "abc"
and it always report the same error.
我使用 AccessController.doPrivileged
因为它是我在原始代码中使用的,当然我使用的是Java 8.
I used AccessController.doPrivileged
because it's what I used in my original code and of course i'm using Java 8.
它在 Watchers
和评估表达式
中说同样的事情。
It says the same thing in Watchers
and Evaluate Expression
.
我尝试使用匿名类版本,调试器正确看到 a
的值
I tried using the "anonymous class" version and the debugger sees the value of a
correctly
private static void m1(String a) {
AccessController.doPrivileged(new PrivilegedAction<String>() {
@Override
public String run() {
System.out.println("blala " + a);
return "abc";
}
});
}
我遗漏了一些关于lambda表达式的东西,或者它是一个IntellIJ IDEA 14错误?
I'm missing something about lambda expressions or it's an IntellIJ IDEA 14 bug?
我现在不想报告错误,因为我已经报告了一个由我的代码而不是IntellIJ IDEA引起的错误,所以我想在之前确定做某事(因为我不经常使用Java 8,所以我可能错了)。
I don't want to report the bug right now because I already reported a bug that was caused by my code instead of IntellIJ IDEA, so I want to be sure before do something (and because I don't use Java 8 so often, so I could be wrong).
推荐答案
这似乎是是一个知道问题。根据JetBrains,这种行为的根本原因在于JDK。有关详细信息,请参阅: IDEA-126257
This appears to be a know issue. According to JetBrains the root causes of this behavior is with the JDK. For more info see: IDEA-126257
这篇关于调试器无法在Lambda中看到局部变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!