Skip to content

Commit e003a17

Browse files
[25] ECJ reports a bogus "The final field t may already have been assigned" error (eclipse-jdt#4611)
* Fixes eclipse-jdt#4585
1 parent 9b41b1d commit e003a17

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ private void complainAboutInitializedFinalFields(FlowInfo flowInfo, ExplicitCons
316316
// if calling 'this(...)', complain about final fields that are already assigned
317317
FieldBinding[] fields = this.binding.declaringClass.fields();
318318
for (FieldBinding field : fields) {
319-
if (!field.isStatic()) {
319+
if (field.isBlankFinal() && !field.isStatic()) {
320320
if (flowInfo.isPotentiallyAssigned(field))
321321
this.scope.problemReporter().duplicateInitializationOfBlankFinalField(field, call);
322322
}

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SuperAfterStatementsTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,4 +3488,29 @@ class X {
34883488
----------
34893489
""");
34903490
}
3491+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4585
3492+
// [25] ECJ reports a bogus "The final field t may already have been assigned" error
3493+
public void testIssue4585() {
3494+
runConformTest(new String[] {
3495+
"X.java",
3496+
"""
3497+
public class X {
3498+
class TestClass<T extends Object> {
3499+
T t;
3500+
TestClass() {}
3501+
3502+
TestClass(T v) {
3503+
switch (0) {
3504+
case 2:
3505+
t = v;
3506+
break;
3507+
}
3508+
this(); // Error here
3509+
}
3510+
}
3511+
}
3512+
"""
3513+
});
3514+
}
34913515
}
3516+

0 commit comments

Comments
 (0)