Debugger cannot see local variable in a Lambda

那年仲夏 提交于 2019-12-18 12:36:18

问题


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.

Example code

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";
        });
    }
}

Try with a breakpoint in System.out.println("blala " + a); and after return "abc" and it always report the same error.

I used AccessController.doPrivileged because it's what I used in my original code and of course i'm using Java 8.

It says the same thing in Watchers and Evaluate Expression.

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";
        }
    });
}

I'm missing something about lambda expressions or it's an IntellIJ IDEA 14 bug?

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).


回答1:


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




回答2:


I can confirm what is written in IDEA bug report linked by Mike Rylander: this is a JDK bug and update to version 8u60_25 of the JDK solves it.



来源:https://stackoverflow.com/questions/26895708/debugger-cannot-see-local-variable-in-a-lambda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!