| 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: | UI | Assignee: | 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
Lars Vogel
New Gerrit change created: https://git.eclipse.org/r/157490 Fabrice and Jeff, please have a look. 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. Created attachment 281787 [details]
Initial Java file without lambda
Created attachment 281788 [details]
After switching to lambda, error flagged
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. 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.
Back to JDT/UI to detect the situation and refuse to convert to lambda. (In reply to Stephan Herrmann from comment #8) > Back to JDT/UI to detect the situation and refuse to convert to lambda. Thanks Stephan @Lars, these are *not* syntax errors. (In reply to Stephan Herrmann from comment #10) > @Lars, these are *not* syntax errors. What kind of errors are they? (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". New Gerrit change created: https://git.eclipse.org/r/157673 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 Released for 4.15M3 Thanks, Jeff. I test this or next week if we have more issues. (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. (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? (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). (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. Verified for 4.15M3 using I20200218-1800 build Looks good in latest I-build. Running the cleanup on JDT UI does not result in any error. Thanks again Jeff. 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? (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. (In reply to Jeff Johnston from comment #24) > Please open a new bug. Done Bug 560322 (In reply to Lars Vogel from comment #25) > (In reply to Jeff Johnston from comment #24) > Done Bug 560322 Handled via Bug 433535. |