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

Bug 419266

Summary: AST from ICompilationUnit#reconcile() contains enum type binding with wrong 'final' modifier
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: major    
Priority: P3 CC: daniel_megert, nikolaymetchev, noopur_gupta
Version: 4.3   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug
Bug Depends on:    
Bug Blocks: 342858    

Description Markus Keller CLA 2013-10-11 14:01:01 EDT
master

This bug causes bug 342858.

The AST from ICompilationUnit#reconcile() contains an enum type binding with a wrong 'final' modifier.

Test case (2 types in separate files):

public class Test {
	public AnonymousEnum2 /*]*/callee()/*[*/ {
		return null;
	}
	public void caller() {
		callee();
	}
}
public enum AnonymousEnum2 {
	TestValue() {
	};
}

The AST for class Test contains a reference to type AnonymousEnum2. The type binding for this reference carries the 'final' modifier, which is wrong in this case.

As Nikolay found in bug 342858 comment 8, the problem shows up around ClassScope#checkAndSetModifiers() line 597. The fieldDecl.initialization for the anonymous TestValue() is null, which is wrong.

fieldDecl.initialization should be set in SourceTypeConverter#convert(SourceField, TypeDeclaration, CompilationResult) line 244, but SourceFieldElementInfo#getInitializationSource() is null for the anonymous enum constant.
=> We either need a way to retain the initializer, or the test in ClassScope#checkAndSetModifiers() needs to be changed.
Comment 1 Markus Keller CLA 2013-10-15 06:58:25 EDT
Note: This problem doesn't show up in an AST from ASTParser (type binding for AnonymousEnum2 is not final there).
Comment 2 Markus Keller CLA 2014-04-28 20:05:42 EDT
http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=72578ba43287462a0c91a7de026e07610ac80a95 has changed org.eclipse.jdt.core.dom.BindingComparator#isEqual(TypeBinding, TypeBinding, HashSet) to use TypeBinding.equalsEquals(..) instead of ==, which effectively works around the problem in bug 342858.

But the 'final' modifier is still wrong.
Comment 3 Eclipse Genie CLA 2019-10-13 14:14:14 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.