Skip to content

[MNG-12594] Fix LegacySupport.setSession() thread safety in DefaultMaven - #12634

Draft
elharo wants to merge 1 commit into
masterfrom
fix-12594
Draft

[MNG-12594] Fix LegacySupport.setSession() thread safety in DefaultMaven#12634
elharo wants to merge 1 commit into
masterfrom
fix-12594

Conversation

@elharo

@elharo elharo commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

fixes #12594

Restores the previous session after execution instead of unconditionally setting it to null.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts how DefaultMaven manages LegacySupport’s current MavenSession, moving from a top-level “clear on exit” approach to a scoped save/restore pattern inside doExecute(...). This is intended to prevent session leakage/corruption in scenarios like nested executions and to better encapsulate session lifecycle handling within the session scope.

Changes:

  • Removed the execute()-level finally { legacySupport.setSession(null); } cleanup.
  • Introduced save/restore of the previous LegacySupport session around the main doExecute(request, session, ...) call.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 223 to +227
legacySupport.setSession(session);

return doExecute(request, session, result, chainedWorkspaceReader);
try {
return doExecute(request, session, result, chainedWorkspaceReader);
} finally {
legacySupport.setSession(previousSession);
Comment on lines +222 to +225
MavenSession previousSession = legacySupport.getSession();
legacySupport.setSession(session);

return doExecute(request, session, result, chainedWorkspaceReader);
try {
return doExecute(request, session, result, chainedWorkspaceReader);
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.

[maven-4.0.x] DefaultMaven: LegacySupport.setSession() thread safety in @Singleton

2 participants