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

Bug 562311

Summary: Initialize Final field in constructor proposals initializes the filed in all constructors incorrectly
Product: [Eclipse Project] JDT Reporter: Kalyan Prasad Tatavarthi <kalyan_prasad>
Component: UIAssignee: Kenneth Styrberg <kenneth>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: kenneth, noopur_gupta
Version: 4.13   
Target Milestone: 4.16 M3   
Hardware: PC   
OS: Windows 10   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=83544
https://git.eclipse.org/r/#/c/160732/
Whiteboard:
Attachments:
Description Flags
Screenshot - multi fix none

Description Kalyan Prasad Tatavarthi CLA 2020-04-20 07:02:16 EDT
Create a class by name Cls1 and paste the below code in the file

public class Cls1 {

	final int c;
	
	public Cls1(int a) {
		
	}
	
	public Cls1() {
		c=10;
	}
}

An error is reported on constructor "public Cla1(int a)" with a quick fix 
"initialize final field 'c' in constructor and upon applying the fix  changes the code to below

public class Cls1 {

	final int c;
	
	public Cls1(int a) {
		this.c = 0;
		
	}
	
	public Cls1() {
		this.c = 0;
		c=10;
	}
}

which is incorrect because the field is already initialized in constructor "Cls1()"
Comment 1 Noopur Gupta CLA 2020-04-20 07:22:13 EDT
Created attachment 282514 [details]
Screenshot - multi fix

You can create a multi-fix (e.g. see screenshot) to fix a problem at multiple locations.  

Also, please remove the full stop from the quick fix text.
Comment 2 Kenneth Styrberg CLA 2020-04-20 09:29:58 EDT
As I'm working with Bug 37872 - [quick fix] add a constructor parameter, I can implement a fix for this as I'm touching that exact code right now.
Comment 3 Kenneth Styrberg CLA 2020-04-20 09:47:52 EDT
https://git.eclipse.org/r/#/c/160732/ should fix this also.
Comment 4 Kalyan Prasad Tatavarthi CLA 2020-04-28 04:15:44 EDT
Fixed by fix for Bug 37872 with the gerrit https://git.eclipse.org/r/#/c/160732/
Comment 5 Kenneth Styrberg CLA 2020-05-23 02:25:49 EDT
Verified in eclipse-SDK-4.16M3-win32-x86_64