Bug 543085 - Cannot inspect captured variable inside lambda when running in different thread
Summary: Cannot inspect captured variable inside lambda when running in different thread
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 4.10   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-29 07:34 EST by Helo Spark CLA
Modified: 2023-03-20 02:24 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Helo Spark CLA 2018-12-29 07:34:18 EST
I'm aware that there has been some work regarding this in #516278, however it is still not working if multiple threads are involved as of Eclipse 2018-12.

Repro:

 - Debug this source code:

import java.util.concurrent.CompletableFuture;

public class TestMain {

    public static void main(String[] args) {
        int test = 2;

        Runnable r = () -> {
            System.out.println(test); // <- add breakpoint here
        };

        CompletableFuture.runAsync(() -> {
            r.run();
        }).join();
    }

}

 - Add a breakpoint at `System.out.println(test);`
 - Notice that hovering `test` does not show it's value, neither it shows up in variables, nor evaluate expression work for that value
Comment 1 Andrey Loskutov CLA 2019-01-13 04:28:26 EST
This corresponds to the known not yet supported cases from bug 516278 comment 2, point 2: the lambda is used not in the defined method but passed to another method.

In this case we can't retrieve the context from the debugger stack, because the stack doesn't have references to "main".

What we have here are only arg$1, arg$2, ... variables which we need to match to the captured variables used inside lambda in order of they use.

To do this we need to parse the lambda body and "count" captured variables as if we were the compiler. After that, we can lookup the captured variable by name and use its index in the captured variables list of our lambda body to find the right arg$ value.

This should be doable for cases where we have sources for the current lambda, so that we can construct AST on it and somehow compute which variables are captured .
Comment 2 Eclipse Genie CLA 2021-01-03 06:20:47 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 3 Eclipse Genie CLA 2023-03-20 02:24:02 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.