Forward port #12961: assign FastTerminal before starting the build thread - #12962
Merged
Conversation
The FastTerminal constructor started the build thread before returning, so MessageUtils.terminal was still null when the build thread ran the builder callback — a race between the constructor returning and the thread scheduling. Split construction from start: MessageUtils now assigns the field before calling FastTerminal.start(), and Thread.start() provides the happens-before edge that makes the assignment visible to the build thread. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gnodet
commented
Aug 30, 2026
gnodet
left a comment
Contributor
Author
There was a problem hiding this comment.
Clean, correct fix for a real race condition. The JMM analysis is sound — Thread.start() provides the happens-before guarantee (JLS 17.4.5) that makes the MessageUtils.terminal assignment visible to the build thread without requiring volatile.
Highlights:
- The two-step init (construct then
start()) is well-contained —FastTerminalis only constructed inMessageUtils.systemInstall(). - The test effectively exercises the fix by verifying
MessageUtils.getTerminal()returns non-null from within the builder callback on the build thread. - This is a clean forward port — the diff is identical to #12961 on maven-4.0.x.
Minor suggestion (non-blocking):
- The new
start()method ispublic, but its only caller isMessageUtils.systemInstall()in the same package. Making it package-private would prevent accidental misuse from other packages.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Forward port of #12961 to master.
Fixes a race condition introduced in #12921: the
FastTerminalconstructor started its build thread before returning, soMessageUtils.terminalwas stillnullwhen the build thread ran the builder callback — a race between the constructor returning and the thread scheduling. This caused aNullPointerExceptionin CI (example):The fix splits construction from start:
MessageUtilsnow assigns the field before callingFastTerminal.start(), andThread.start()provides the happens-before edge that makes the assignment visible to the build thread without additional synchronization.FastTerminal: extractstart()method from constructor, document the publish-before-start contractMessageUtils.systemInstall(): assignterminalfield, then callstart()terminalAssignmentIsVisibleFromBuilderCallbackthat assertsMessageUtils.getTerminal()is non-null from the builder callbackTest plan
FastTerminalReentrancyTest— all 5 tests pass (4 existing + 1 new)maven-jlinemodule test suite passes🤖 Generated with Claude Code