Debugger cannot see local variable in Lambda

I noticed that when I hover over a local variable, when my debugger is stopped inside the lambda, it tells Cannot find local variable 'variable_name' , even if it is displayed inside the lambda and is used.

Code example

 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 always report the same error.

enter image description here

I used AccessController.doPrivileged because this is what I used in my source code, and of course I use Java 8.

He says the same thing in Watchers and Evaluate Expression .

I tried using the version of the โ€œanonymous classโ€, and the debugger correctly understood the value of a

enter image description here

 private static void m1(String a) { AccessController.doPrivileged(new PrivilegedAction<String>() { @Override public String run() { System.out.println("blala " + a); return "abc"; } }); } 

Am I missing something about lambda expressions or is this an IntellIJ IDEA 14 error?

I donโ€™t want to report an error right now, because I already reported an error caused by my code, not IntellIJ IDEA, so I want to be sure before I do something (and because I donโ€™t use Java 8 so often , so I could be wrong).

+6
source share
2 answers

This seems to be a problem with the information. According to JetBrains, the reason for this behavior is the JDK. For more information see: IDEA-126257

+8
source

I can confirm what is written in the IDEA bug report associated with Mike Rylander: this is a JDK error, and updating to version 8u60_25 of the JDK resolves it .

+3
source

Source: https://habr.com/ru/post/978109/


All Articles