Bug 304761 - Debugger can't see final synthetically-accessed variables from anonymous nested class instance
Summary: Debugger can't see final synthetically-accessed variables from anonymous nest...
Status: REOPENED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 4.8   Edit
Hardware: PC Linux
: P3 normal with 8 votes (vote)
Target Milestone: ---   Edit
Assignee: Sarika Sinha CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 322244 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-03-04 18:37 EST by Luke Hutchison CLA
Modified: 2022-12-18 14:56 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luke Hutchison CLA 2010-03-04 18:37:55 EST
Build Identifier: I20100129-1300

The debugger cannot display the value for idx when the runnable thread is paused.  Internally it looks like it is encoded as "val$idx", and this value is available in the variable list, but that doesn't help with selecting an expression, right-clicking and going "Display", as the value can't be calculated.

I guess the debugger needs to look for val$variable if variable doesn't exist, and do so for every variable in a selected expression when evaluating an expression for "Display"?

for (int i = 0; i < numCols; i++) {
    final int idx = i;
    workQueue.submit(new Runnable() {
        @Override
        public void run() {
            System.out.println(idx);
            //                 ^^^
        }
    }
}


Reproducible: Always
Comment 1 Darin Wright CLA 2010-08-10 16:39:04 EDT
*** Bug 322244 has been marked as a duplicate of this bug. ***
Comment 2 Luke Hutchison CLA 2018-09-14 05:11:37 EDT
A complete working example:


import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class InnerThreadBug {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        final int idx = 0;
        ExecutorService threadPool = Executors.newFixedThreadPool(1);
        threadPool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(idx);  // Set a breakpoint here
            }
        }).get();
    }
}



Is this a dup of bug #538899?
Comment 3 Sarika Sinha CLA 2018-09-14 05:29:26 EDT
Unfortunately, this is not a duplicate.
This is limited by java features that Eclipse is not bale to display it. If you change int to Integer it will work.
Comment 4 Luke Hutchison CLA 2018-09-14 05:46:08 EDT
I just tested this -- changing int to Integer does not allow idx to be displayed, so I'm reopening, since based on your comment, this is supposed to work?

(I'm also curious, what technically makes it impossible for Eclipse to show idx, when the println statement is able to print it?)
Comment 5 Sarika Sinha CLA 2018-09-14 09:38:21 EDT
If you have in a method like this, it will work for int as well :
public void test1() {
		int numCols = 5;
		for (int i = 0; i < numCols; i++) {
		    final int idx = i;
		    
		    Consumer<Integer> consumer = new Consumer<Integer>() {
				@Override
				public void accept(Integer n) {
					System.out.println(idx + n); // idx is visible
				}
		};
		consumer.accept(5);
		}
	}

But if you have it in main method -
public static void main(String[] args) throws InterruptedException, ExecutionException {
        final Integer idx = 0;
        ExecutorService threadPool = Executors.newFixedThreadPool(1);
        threadPool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(idx);  // Set a breakpoint here
            }
        }).get();
    }

Only If you have the idx as Integer it will be visibility. The way debugger fetches the value from the vm when a thread is suspended is different from the normal execution.
Comment 6 Sarika Sinha CLA 2018-11-19 04:24:42 EST
Not able to find time right now.
Comment 7 Eclipse Genie CLA 2020-11-09 17:25:45 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 8 Luke Hutchison CLA 2020-11-09 17:52:06 EST
Pretty sure this is still a problem. (Commenting so that this is not auto-closed.)
Comment 9 Eclipse Genie CLA 2022-12-18 14:56:25 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.