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

Bug 563285

Summary: CCE in InitializeFinalFieldProposal for enum
Product: [Eclipse Project] JDT Reporter: Noopur Gupta <noopur_gupta>
Component: UIAssignee: Kenneth Styrberg <kenneth>
Status: VERIFIED FIXED QA Contact: Roland Grunberg <rgrunber>
Severity: normal    
Priority: P3    
Version: 4.16   
Target Milestone: 4.16 M3   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/163194
https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=359efe357dd13123570f8cccc80bd94425e65350
Whiteboard:
Bug Depends on: 37872    
Bug Blocks:    

Description Noopur Gupta CLA 2020-05-18 07:05:23 EDT
package pp;
public enum Organization {
	toReal, toIrrational, toImaginary, toComplex;

	public final String instructions;

	public final String formOptions;

	private Organization(String instructions, String formOptions) {
		this.instructions = instructions;
		this.formOptions = formOptions;
	}

	Organization() {
		// TODO Auto-generated constructor stub
	}
}

- Hover on the error at "Organization" to get the quick fixes. We get the following exception in error log view:

java.lang.ClassCastException: class org.eclipse.jdt.core.dom.EnumDeclaration cannot be cast to class org.eclipse.jdt.core.dom.TypeDeclaration (org.eclipse.jdt.core.dom.EnumDeclaration and org.eclipse.jdt.core.dom.TypeDeclaration are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @1f4bdf41)
	at org.eclipse.jdt.internal.ui.text.correction.proposals.InitializeFinalFieldProposal.doUpdateConstructorWithParameter(InitializeFinalFieldProposal.java:253)
	at org.eclipse.jdt.internal.ui.text.correction.proposals.InitializeFinalFieldProposal.getRewrite(InitializeFinalFieldProposal.java:117)
	at org.eclipse.jdt.internal.ui.text.correction.proposals.InitializeFinalFieldProposal.hasProposal(InitializeFinalFieldProposal.java:101)
	at org.eclipse.jdt.internal.ui.text.correction.UnInitializedFinalFieldSubProcessor.getProposals(UnInitializedFinalFieldSubProcessor.java:73)
	at org.eclipse.jdt.internal.ui.text.correction.QuickFixProcessor.process(QuickFixProcessor.java:395)
...
Comment 1 Kenneth Styrberg CLA 2020-05-18 10:40:16 EDT
I'll take a look
Comment 2 Eclipse Genie CLA 2020-05-18 11:29:55 EDT
New Gerrit change created: https://git.eclipse.org/r/163194
Comment 4 Roland Grunberg CLA 2020-05-20 10:17:36 EDT
It might be useful to look at other places throughout the codebase where the proposal logic casts to TypeDeclaration, and the user might be in the context of some "sibling" type (eg. EnumDeclaration)  where AbstractTypeDeclaration is safer.
Comment 5 Kenneth Styrberg CLA 2020-05-23 02:15:32 EDT
Verified in eclipse-SDK-4.16M3-win32-x86_64