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

Bug 560018

Summary: Multiple errors running clean-up for lambda and method references on Platform UI repo
Product: [Eclipse Project] JDT Reporter: Lars Vogel <Lars.Vogel>
Component: UIAssignee: Jeff Johnston <jjohnstn>
Status: VERIFIED FIXED QA Contact: Jeff Johnston <jjohnstn>
Severity: normal    
Priority: P3 CC: daniel_megert, fabrice.tiercelin, jjohnstn, Lars.Vogel, stephan.herrmann
Version: 4.14   
Target Milestone: 4.15 M3   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/157490
https://git.eclipse.org/r/157673
https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=fb634dda84d8a1179432298e9ba72b284c007676
Whiteboard:
Bug Depends on:    
Bug Blocks: 433535, 560322    
Attachments:
Description Flags
Initial Java file without lambda
none
After switching to lambda, error flagged
none
self-contained example none

Description Lars Vogel CLA 2020-02-11 07:13:00 EST
See upcoming Gerrit for the example of the created syntax error.
Comment 1 Eclipse Genie CLA 2020-02-11 07:14:59 EST
New Gerrit change created: https://git.eclipse.org/r/157490
Comment 2 Lars Vogel CLA 2020-02-11 07:15:10 EST
Fabrice and Jeff, please have a look.
Comment 3 Jeff Johnston CLA 2020-02-11 13:24:46 EST
This bug appears to be a compiler issue.  In the case of using the anonymous class, the compiler does not have issue with the wrappedMap variable but in the case of the lambda, it flags it.  This is inconsistent.  I am going to reroute this to jdt.core for their analysis.
Comment 4 Jeff Johnston CLA 2020-02-11 14:08:10 EST
Created attachment 281787 [details]
Initial Java file without lambda
Comment 5 Jeff Johnston CLA 2020-02-11 14:09:31 EST
Created attachment 281788 [details]
After switching to lambda, error flagged
Comment 6 Jeff Johnston CLA 2020-02-11 14:13:21 EST
Moving this to jdt.core.  Compiler is inconsistent on its treatment of private final variable used inside an anonymous class vs a lambda replacement.

I have added two attachments.  The second attachment after switching to use a lambda instead of an anonymous class gets flagged for possible uninitialized final variable: wrappedMap which is initialized in the constructor.
Comment 7 Stephan Herrmann CLA 2020-02-11 14:32:46 EST
Created attachment 281789 [details]
self-contained example

I minimally extended the example to become self-contained.

Now, guess what javac reports:

MappedSet.java:24: error: variable wrappedMap might not have been initialized
                        Object mapValue = wrappedMap.get(added);
                                          ^
1 error


While I agree that this is inconsistent, the inconsistency seems to be Java's not JDT's.

Actually, I believe this difference is necessary, because the lambda cannot use outer this to get the field value when needed, but has to capture the value ahead of time, at which point the constructor has not run, indeed.
Comment 8 Stephan Herrmann CLA 2020-02-11 14:33:25 EST
Back to JDT/UI to detect the situation and refuse to convert to lambda.
Comment 9 Jeff Johnston CLA 2020-02-11 15:49:39 EST
(In reply to Stephan Herrmann from comment #8)
> Back to JDT/UI to detect the situation and refuse to convert to lambda.

Thanks Stephan
Comment 10 Stephan Herrmann CLA 2020-02-11 16:09:04 EST
@Lars, these are *not* syntax errors.
Comment 11 Lars Vogel CLA 2020-02-11 16:16:11 EST
(In reply to Stephan Herrmann from comment #10)
> @Lars, these are *not* syntax errors.

What kind of errors are they?
Comment 12 Stephan Herrmann CLA 2020-02-11 16:24:34 EST
(In reply to Lars Vogel from comment #11)
> (In reply to Stephan Herrmann from comment #10)
> > @Lars, these are *not* syntax errors.
> 
> What kind of errors are they?

Without going into details: semantic errors. The one about wrappedMap could be called a flow error (detected by flow analysis).

If you are really unsure say "compile error".
Comment 13 Eclipse Genie CLA 2020-02-13 16:44:09 EST
New Gerrit change created: https://git.eclipse.org/r/157673
Comment 15 Jeff Johnston CLA 2020-02-18 10:46:33 EST
Released for 4.15M3
Comment 16 Lars Vogel CLA 2020-02-18 10:56:01 EST
Thanks, Jeff. I test this or next week if we have more issues.
Comment 17 Dani Megert CLA 2020-02-18 10:57:00 EST
(In reply to Eclipse Genie from comment #14)
> Gerrit change https://git.eclipse.org/r/157673 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=fb634dda84d8a1179432298e9ba72b284c007676
> 
We are in milestone freeze mode. You should not have merged that.
Comment 18 Jeff Johnston CLA 2020-02-18 11:42:05 EST
(In reply to Dani Megert from comment #17)
> (In reply to Eclipse Genie from comment #14)
> > Gerrit change https://git.eclipse.org/r/157673 was merged to [master].
> > Commit:
> > http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=fb634dda84d8a1179432298e9ba72b284c007676
> > 
> We are in milestone freeze mode. You should not have merged that.

Sorry about that.  Should I revert?
Comment 19 Dani Megert CLA 2020-02-18 11:48:52 EST
(In reply to Jeff Johnston from comment #18)
> (In reply to Dani Megert from comment #17)
> > (In reply to Eclipse Genie from comment #14)
> > > Gerrit change https://git.eclipse.org/r/157673 was merged to [master].
> > > Commit:
> > > http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=fb634dda84d8a1179432298e9ba72b284c007676
> > > 
> > We are in milestone freeze mode. You should not have merged that.
> 
> Sorry about that.  Should I revert?
I leave that up to you. Assess whether the fix can cause any regression(s).
Comment 20 Jeff Johnston CLA 2020-02-18 13:59:16 EST
(In reply to Dani Megert from comment #19)
> (In reply to Jeff Johnston from comment #18)
> > (In reply to Dani Megert from comment #17)
> > > (In reply to Eclipse Genie from comment #14)
> > > > Gerrit change https://git.eclipse.org/r/157673 was merged to [master].
> > > > Commit:
> > > > http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=fb634dda84d8a1179432298e9ba72b284c007676
> > > > 
> > > We are in milestone freeze mode. You should not have merged that.
> > 
> > Sorry about that.  Should I revert?
> I leave that up to you. Assess whether the fix can cause any regression(s).

Ok, I am opting to leave it in.
Comment 21 Jeff Johnston CLA 2020-02-18 20:36:16 EST
Verified for 4.15M3 using I20200218-1800 build
Comment 22 Lars Vogel CLA 2020-02-19 02:08:36 EST
Looks good in latest I-build.

Running the cleanup on JDT UI does not result in any error.

Thanks again Jeff.
Comment 23 Lars Vogel CLA 2020-02-19 02:15:14 EST
Spoke to early, we have less errors but still one. If you run the cleanup on GenerateToStringDialog you get errors.

Jeff, do you prefer a new bug or shall I reopen this one?
Comment 24 Jeff Johnston CLA 2020-02-19 10:33:57 EST
(In reply to Lars Vogel from comment #23)
> Spoke to early, we have less errors but still one. If you run the cleanup on
> GenerateToStringDialog you get errors.
> 
> Jeff, do you prefer a new bug or shall I reopen this one?

Please open a new bug.  This bug fixed the problem of accessing a final field within a lambda that was not initialized at the field declaration.  The new issue is for accessing a field that will be defined after the lambda referencing it.
Comment 25 Lars Vogel CLA 2020-02-19 10:43:09 EST
(In reply to Jeff Johnston from comment #24)

> Please open a new bug.  

Done Bug 560322
Comment 26 Lars Vogel CLA 2020-02-24 10:48:00 EST
(In reply to Lars Vogel from comment #25)
> (In reply to Jeff Johnston from comment #24)

> Done Bug 560322
Handled via Bug 433535.