Skip to content

Fix #12607: prevent session scope leak on MavenChainedWorkspaceReader constructor exception - #12863

Merged
gnodet merged 1 commit into
masterfrom
fix/12607
Aug 28, 2026
Merged

gnodet merged 1 commit into
masterfrom
fix/12607

Conversation

@gnodet

@gnodet gnodet commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Move MavenChainedWorkspaceReader construction before sessionScope.enter() in DefaultMaven.doExecute() to prevent a session scope thread-local leak when the constructor throws

Problem

sessionScope.enter() was called at line 212, followed by new MavenChainedWorkspaceReader(...) at lines 213-214, before the try block at line 215. If the constructor threw any exception, the sessionScope.exit() in the finally block would never execute, leaking the session scope's thread-local ScopeState.

Fix

Reorder the two statements so the workspace reader is constructed first. Since MavenChainedWorkspaceReader has no dependency on the session scope, this is safe. If its constructor throws, the scope was never entered, so no cleanup is needed.

Test plan

  • Verified the fix by code inspection — the workspace reader constructor has no session scope dependency
  • All 612 existing tests in maven-core pass (including DefaultMavenTest and SessionScopeProxyTest)
  • Minimal one-line reorder diff — no behavioral change to the normal path

🤖 Generated with Claude Code

… constructor exception

Move MavenChainedWorkspaceReader construction before sessionScope.enter()
so that if the constructor throws, the session scope is never entered and
exit() does not need to run. Previously, the constructor call sat between
enter() and the try block, meaning any exception would skip the finally
block's sessionScope.exit(), leaking thread-local state.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@gnodet gnodet added the bug Something isn't working label Aug 27, 2026
@gnodet gnodet added this to the 4.0.0-rc-7 milestone Aug 27, 2026
@gnodet
gnodet marked this pull request as ready for review August 27, 2026 13:57

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Summary

Correct and safe one-line reorder that eliminates a real thread-local leak. The MavenChainedWorkspaceReader constructor has no session scope dependency, and the reorder places sessionScope.enter() immediately before the try block, closing the exception gap.

No blocking issues found.

🔀 Backport Status

⚠️ This bug fix targets master but no backport PR was found for:

  • maven-4.0.x — has the identical vulnerable pattern (sessionScope.enter() followed by constructor before try)

Note: maven-3.9.x and maven-3.10.x do not have this bug — sessionScope.enter() directly precedes try in those branches.

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

@gnodet gnodet modified the milestones: 4.0.0-rc-7, 4.1.0 Aug 28, 2026
@gnodet
gnodet merged commit 5ae676d into master Aug 28, 2026
24 checks passed
@gnodet
gnodet deleted the fix/12607 branch August 28, 2026 13:26
gnodet added a commit that referenced this pull request Aug 28, 2026
… constructor exception (#12863) (#12895)

Move MavenChainedWorkspaceReader construction before sessionScope.enter()
so that if the constructor throws, the session scope is never entered and
exit() does not need to run. Previously, the constructor call sat between
enter() and the try block, meaning any exception would skip the finally
block's sessionScope.exit(), leaking thread-local state.

Co-authored-by: Claude Opus 4.6 <[email protected]>
gnodet added a commit to gnodet/maven that referenced this pull request Oct 26, 2026
Restore two upstream commits that were accidentally dropped when
rebasing onto stacked/build-report:

1. DefaultMaven.java – session scope leak fix (apache#12629/apache#12863)
   Re-adds the outer try-finally around MavenChainedWorkspaceReader
   construction and the CloseableSession block so that
   sessionScope.exit() is always called even when the reader
   constructor throws. Without the try block the finally clause on
   the ARM try-with-resources is never reached.
   Restores commits 850d3de and 5ae676d from upstream/master.

2. DefaultMavenPluginManager.java – MNG-8765 pre-interpolation and
   concurrent realm disposal (beee0f0 + 6399a8e)
   Restores the interpolateConfiguration() method (and its helpers
   EXPRESSION_PATTERN / collectModelTimePropertyNames /
   containsRuntimeExpression / interpolateXmlNode) together with the
   two call-sites in loadV4Mojo and loadV3Mojo so that runtime
   ${...} property references are resolved before type converters
   run. Also restores the duplicate-realm disposal block in
   setupExtensionsRealm and the missing imports (HashSet, Properties,
   Set, Matcher, Pattern, NoSuchRealmException).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants