Community
Participate
Working Groups
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
*** Bug 322244 has been marked as a duplicate of this bug. ***
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?
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.
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?)
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.
Not able to find time right now.
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.
Pretty sure this is still a problem. (Commenting so that this is not auto-closed.)