Skip to content

Conversation

@coehlrich
Copy link
Contributor

@coehlrich coehlrich commented Dec 17, 2025

What it does

Fixes #4700

How to test

Attempt to compile

public class Test {
	private final Object a;
	public Test() {
		a = new Object();
		class Test2 {
			private final Object b;
			public Test2() {
				System.out.println();
				super();
				b = new Object();
			}
		}
	}
}

Author checklist

@coehlrich coehlrich force-pushed the fix-constructor-prologue-local-constructor branch from f0b0f26 to 962c1d9 Compare December 17, 2025 06:04
@iloveeclipse
Copy link
Member

Two previous Jenkins build silently did nothing...

I've manually triggered Jenkins build https://ci.eclipse.org/jdt/job/eclipse.jdt.core-Github/job/PR-4701/3/console

If the problem persists, please file a ticket at https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/issues/ or ping me here.

@stephan-herrmann stephan-herrmann self-requested a review December 24, 2025 14:27
AbstractMethodDeclaration method = this.methods[i];
if (method.isConstructor()) {
FlowInfo ctorInfo = flowInfo.copy();
FlowInfo ctorInfo = flowInfo.unconditionalFieldLessCopy();
Copy link
Contributor

@stephan-herrmann stephan-herrmann Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, this effectively fixes the issue, but something smells strangely here: the flow info that produced the bogus error concerned the field a of the outer class, i.e., we were actually misinterpreting the field index 0.

@coehlrich do you think we can streamline this code section wrt field of the enclosing class? See this comment few lines above:

// discards info about fields of inclosing classes

Given that no analysis within the current type should bother about fields of the enclosing class (?), could we find a single location for calling unconditionalFieldLessCopy() once and for all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently internalAnalyseCode uses flowInfo without calling unconditionalFieldLessCopy in 5 locations:

  • 2 times as arguments for InitializationFlowContext which only uses it in getInitsForFinalBlankInitializationCheck which also looks for the correct parent before returning the corresponding FlowInfo
  • 2 times for calls to reachMode which is copied when calling unconditionalFieldLessCopy
  • 1 time as an argument when calling analyseCode on all methods that aren't for initialization

None of the regression tests failed when adding flowInfo = flowInfo.unconditionalFieldLessCopy() to the top of internalAnalyseCode

While looking into this I did also notice that constructors with prologues aren't checked to see if all of the blank final fields have been initialized

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all uses of the methods relating to fields in FlowInfo in ast either only look at fields in the same class or have a check for if the current class is the same as the one containing the field with some also only calling it on the output of getInitsForFinalBlankInitializationCheck. for subclasses of FlowContext I couldn't get it to recognize final field assignments for the outer class in finally blocks or in the condition of a while loop (which still did give a compile error).

@coehlrich coehlrich force-pushed the fix-constructor-prologue-local-constructor branch from 962c1d9 to 840812c Compare January 4, 2026 03:41
@coehlrich coehlrich force-pushed the fix-constructor-prologue-local-constructor branch from 840812c to e2dd748 Compare January 4, 2026 03:45
@coehlrich
Copy link
Contributor Author

Jenkins had another issue with building this PR. For a while after the builds failed the https://ci.eclipse.org/jdt/ was timing out while https://ci.eclipse.org was fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ECJ fails to compile final field assignment in constructor with prologue in local class in constructor that has assigned a final field

3 participants