Bug 561715 - [1.8] Cannot inspect variable in none lambda blocks
Summary: [1.8] Cannot inspect variable in none lambda blocks
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 4.15   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 4.16 M1   Edit
Assignee: Gayan Perera CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-02 13:30 EDT by Gayan Perera CLA
Modified: 2020-04-13 08:06 EDT (History)
3 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-02 13:30:54 EDT
Debug into the filter step in the following stream expression

			long count = Arrays.asList(1, 2, 33).stream()
					.filter(i -> i > y ? true : false).count();

The i variable can be seen in the variables view, but cannot be inspected or used in a expression under the DebugShell.
Comment 1 Gayan Perera CLA 2020-04-02 13:31:27 EDT
This works fine if the filter step was written as a lambda block.
Comment 2 Gayan Perera CLA 2020-04-02 13:33:57 EDT
It works if we write the statement like this

			long count = Arrays.asList(1, 2, 33).stream()
					.filter(i -> { 
						return i > y ? true : false;
						}).count();


But not like this

	long count = Arrays.asList(1, 2, 33).stream()
			.filter(i -> { return i > y ? true : false;}).count();
Comment 3 Gayan Perera CLA 2020-04-02 14:14:10 EDT
Seems like this bug is there are bug561542
Comment 4 Gayan Perera CLA 2020-04-02 14:14:53 EDT
Seems like this bug is caused by bug561542. Will do some more testing
Comment 5 Gayan Perera CLA 2020-04-02 15:04:06 EDT
Seems the problem is the variable y which is define before the lambda.

This is the code i'm using in the unit test to reproduce this bug.

import java.util.Arrays;
import java.util.function.Predicate;

public class Bug561715 {
	public static void main(String[] args) {
		String y = "111";
		Arrays.asList("111", "222", "aaa").stream().filter(a -> a.equals(y)).count();
	}
}

adding break point at stream expression line and debug into filter lambda will show that you cannot evaluate\inspect the variable a
Comment 6 Gayan Perera CLA 2020-04-02 15:25:05 EDT
further looking at the code it seems that the y variable is appearing as a arg$1, it is not properly resolved to variable y or atleast val$y as we normally expect.
Comment 7 Gayan Perera CLA 2020-04-02 15:51:04 EDT
I have a fix, i will provide a gerrit.
Comment 8 Eclipse Genie CLA 2020-04-02 16:00:16 EDT
New Gerrit change created: https://git.eclipse.org/r/160402
Comment 9 Sarika Sinha CLA 2020-04-03 02:48:11 EDT
I am not able to reproduce this problem. I am able to use y in debug Shell and Conditional breakpoint also. 
However the hover shows it as "y" and not "arg$y" and this is not fixed after the patch as well.


Gerrit change looks logical improvement from previous version and I am fine with it.
Comment 10 Gayan Perera CLA 2020-04-03 03:09:54 EDT
@Sarika
Can you the my unit test without the fix in your environment?
Comment 11 Sarika Sinha CLA 2020-04-03 05:37:31 EDT
(In reply to Gayan Perera from comment #10)
> @Sarika
> Can you the my unit test without the fix in your environment?

Yes, tried from Comment#5 in new workspace with Build id: I20200402-2250
Comment 12 Gayan Perera CLA 2020-04-03 05:45:41 EDT
@Sarika strange. Because the actual unit test i wrote failed when i ran it as plugin test until i fixed the code on yday i build
Comment 13 Sarika Sinha CLA 2020-04-03 06:08:40 EDT
(In reply to Gayan Perera from comment #12)
> @Sarika strange. Because the actual unit test i wrote failed when i ran it
> as plugin test until i fixed the code on yday i build

Yes, as a test when I run it fails without the fix and passes wit hthe fix.

But in workspace I am not able to reproduce. As I think the lambda is nested in ta norma statement and Conditional BP is able to evaluate it.
Comment 15 Sarika Sinha CLA 2020-04-03 08:04:48 EDT
Thanks Gayan!
Comment 16 Sarika Sinha CLA 2020-04-06 07:36:41 EDT
Build id: I20200404-1800