Bug 562231 - Captured implicit object reference to enclosing object of the lambda is shown as arg$1 in Variables view
Summary: Captured implicit object reference to enclosing object of the lambda is shown...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 4.9   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-16 14:24 EDT by Gayan Perera CLA
Modified: 2024-03-29 13:20 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gayan Perera CLA 2020-04-16 14:24:18 EDT
Take the following example

package workbench;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LambdaTest {
	Handler handler = new Handler();
	
	public static void main(String[] args) {
		(new LambdaTest()).run();
	}
	
	private ActionListener objectSetHandler = event -> {
		if (event.getID() > 0) {
			LambdaTest.this.handler.equals("");
			System.out.println(event);
		}
	};

	public void run() {
		objectSetHandler.actionPerformed(new ActionEvent(new Object(), 1, ""));
	}
}

It is unable to inspect "LambdaTest.this.handler" inside the objectSetHandler lambda instance.
Comment 1 Gayan Perera CLA 2020-04-16 14:26:38 EDT
The variable is shown as arg$1 inside the lambda object in variables view.
Comment 2 Andrey Loskutov CLA 2020-04-16 14:32:30 EDT
Is this bug 562056 comment 63? Do you see errors in the log?
Comment 3 Gayan Perera CLA 2020-04-16 14:34:25 EDT
No this basically get skipped because there are not synthetic local variables which i'm not pretty sure that it is. Not a expert on the JDT still.
Comment 4 Gayan Perera CLA 2020-04-16 14:35:21 EDT
I found this while i was trying to reproduce bug 562056 comment 63. But i couldn't reproduce that with my simple code.
Comment 5 Andrey Loskutov CLA 2020-04-16 15:19:57 EDT
(In reply to Andrey Loskutov from comment #2)
> Is this bug 562056 comment 63? Do you see errors in the log?

Yes, it is the "missing" test for that bug and basically the example from Simeon. 
Yes, there are errors in the log, and inspection doesn't work.
Yes, the fix for bug 562056 fixes errors on inspection here.
No, implicit object instance of the enclosing class is not properly resolved to a variable name because there is no variable defined for that implicit reference.
We may try to add something like "val.LambdaTest.this" or even skip the "val".

Reduced example:

package x;

public class LambdaTest {
	Object handler = new Object();

	public static void main(String[] args) {
		(new LambdaTest()).run();
	}

	private Runnable objectSetHandler = () -> {
		String string = handler.toString(); // breakpoint here, inspect handler.toString()
		System.out.println(string);
	};

	public void run() {
		objectSetHandler.run();
	}
}

2 Errors:
Compile error during code evaluation: Syntax error on token "}", delete this token
Compile error during code evaluation: Syntax error on token "1", invalid VariableDeclaratorId

@Simeon: thanks for this example, I will add it to the test for bug 562056.
Comment 6 Gayan Perera CLA 2020-04-17 02:10:27 EDT
@Andrey can we fix this issue ? Does your fix on xtext issue handle this as well ?
Comment 7 Eclipse Genie CLA 2022-04-08 02:31:39 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.
Comment 8 Eclipse Genie CLA 2024-03-29 13:20:38 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.