Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 519687

Summary: Method reference parameter value shown as null in Inspect but has value in Variables view
Product: [Eclipse Project] JDT Reporter: Irina Marudina <public>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: public, register.eclipse, sarika.sinha
Version: 4.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug
Attachments:
Description Flags
Step into Thread's constructor
none
"target" right before use
none
Inspect of "target" right before use
none
Hover on "target" right after use none

Description Irina Marudina CLA 2017-07-14 07:43:27 EDT
Created attachment 269354 [details]
Step into Thread's constructor

Steps to reproduce:

1. Debug the following program with breakpoint inside the corresponding Thread's constructor:
---
public class ConcurrentGreeter {
	public void greet() {
		System.out.println("Hello, world!");
	}
	
	public static void main(String[] args) {
		ConcurrentGreeter greeter = new ConcurrentGreeter();		
		Thread t = new Thread(greeter::greet);
		t.start();
	}
}
---
2. Hover over "target" parameter inside Thread's constructor
3. Add "target" to Expressions view
4. Inspect "target" parameter value

Actual behavior: Hover gives value "null", Expression view shows "null", inspect gives an alert: "Error evaluating: -1"

Expected behavior: Hover, Expressions and Inspect of "target" should give the same value as shown in Variables view for the corresponding parameter(arg0), which is not null. In my case it was "ConcurrentGreeter$$Lambda$1/1749186397@1761e840".

Further investigation: When I continue debugging inside the Thread's "private void init(ThreadGroup g, Runnable target, String name, long stackSize, AccessControlContext acc)" method, right after line "this.target = target;", the value of target switches from null to the one shown in Variables view. It can now be correctly seen on hover and in Expressions. After this execution point, I can now also Inspect the "target" in the previous stack frames.
Comment 1 Irina Marudina CLA 2017-07-14 07:44:14 EDT
Created attachment 269355 [details]
"target" right before use
Comment 2 Irina Marudina CLA 2017-07-14 07:44:48 EDT
Created attachment 269356 [details]
Inspect of "target" right before use
Comment 3 Irina Marudina CLA 2017-07-14 07:46:08 EDT
Created attachment 269357 [details]
Hover on "target" right after use
Comment 4 Sarika Sinha CLA 2017-07-17 00:42:09 EDT
I am not bale to reproduce this problem, I can hover, inspect and see the value in expression view.
I have used latest Photon build. 
Can you try on the latest build ?
Comment 5 Irina Marudina CLA 2017-07-17 10:48:16 EDT
Have you tried to reproduce it on 4.7 Oxygen? I have tested on two separate Windows machines and it gives the same behavior as explained.
Comment 6 Till Brychcy CLA 2017-07-17 10:57:24 EDT
I can reproduce it (on the master).
Comment 7 Irina Marudina CLA 2017-07-17 11:09:58 EDT
Further observation: when I create the Thread with a Runnable object - the same target == null is observed.
Comment 8 Till Brychcy CLA 2017-07-17 14:23:52 EDT
The problem does not appear when launching the test with java 9.
So it looks like this is a jre problem and not an eclipse bug.
Comment 9 Till Brychcy CLA 2017-07-17 14:47:28 EDT
I've found the problem:
As visible in the screenshot in the variables view, the parameter is called "arg0" (probably the java 8 rt.jar isn't compiled with debug information).
But Thread has a field named target, so its value is printed instead.
Comment 10 Irina Marudina CLA 2017-07-17 15:05:29 EDT
Seems like a reasonable explanation to me. Still there is something confusing - after the line "this.target = target;" is executed, "target" argument is shown by Eclipse as changing from null to a valid reference. I guess it now shows the newly set value of "this.target" instead of arg1.

If the debug info is missing, shouldn't the value of "target" argument stay unknown for the whole debug session?
Comment 11 Till Brychcy CLA 2017-07-17 15:18:15 EDT
(In reply to Irina Marudina from comment #10)
> Seems like a reasonable explanation to me. Still there is something
> confusing - after the line "this.target = target;" is executed, "target"
> argument is shown by Eclipse as changing from null to a valid reference. I
> guess it now shows the newly set value of "this.target" instead of arg1.
> 
> If the debug info is missing, shouldn't the value of "target" argument stay
> unknown for the whole debug session?

If the identifier was unknown, no hover would be shown at all.
Field names are always known to the run time.
So it is always the value of the "target" field that is shown here.

I've debugged a bit, the "arg0" is created in 
org.eclipse.jdi.internal.MethodImpl.inferArguments()
Comment 12 Irina Marudina CLA 2017-07-17 16:05:27 EDT
Shouldn't the debugger differentiate between field this.target and argument target? If it did, no hover/inspect/watch would be possible for the argument when debug info is missing in the jar.
Comment 13 Eclipse Genie CLA 2020-04-08 10:01:07 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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.