GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use try-with-resources for AuthenticationContext by slachiewicz · Pull Request #12843 · apache/maven

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Aug 26, 2026

Copy link
Copy Markdown
Member

Make sure AuthenticationContext instances are properly closed even when exceptions are thrown during property retrieval, using try-with-resources.

This is a modern rebase / successor of stale PR #669 targeting the active master branch:

  • The AuthenticationContext try-with-resources conversions in LegacyRepositorySystem and MavenRepositorySystem have been updated for current paths (compat/maven-compat and impl/maven-core).
  • Added try-with-resources conversion for LegacyRepositorySystemSessionExtender.
  • The obsolete conversions from Use try-with-resources #669 (ProjectBuildingException, DefaultMavenPluginManager) were omitted as those classes were already refactored.

Closes #669

  • I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@slachiewicz
Use try-with-resources for AuthenticationContext
4a95b16
Closes #669
@slachiewicz slachiewicz added the bug Something isn't working label Aug 26, 2026
gnodet
gnodet approved these changes Aug 26, 2026
View reviewed changes

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Clean, correct conversion of manual AuthenticationContext.close() calls to try-with-resources across three files. This ensures the context is properly closed even when exceptions occur during credential retrieval, fixing a resource leak on the exception path.

The real value of this change is exception safety — in the original code, if any authCtx.get() call or the Authentication constructor threw an exception, the close() call would be skipped, leaking the context.

This PR correctly supersedes the stale PR #669, which targeted a much older codebase.

📋 PR Metadata

Aspect Current Suggested
Milestone (none) 4.1.0

🔀 Backport Status

⚠️ This bug fix targets master but no backport PRs were found for:

  • maven-4.0.x — no backport PR or label found (should cherry-pick cleanly since file paths match master)

Note: The same unclosed-on-exception pattern exists on maven-3.9.x and maven-3.10.x at the old file paths (pre-reorganization layout), so those branches may also benefit from a similar fix.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
This was referenced Aug 26, 2026
[4.0.x] Use try-with-resources for AuthenticationContext #12844
Merged
[3.10.x] Use try-with-resources #12845
Merged
[3.9.x] Use try-with-resources #12846
Merged
Use try-with-resources #669
Closed
@slachiewicz
slachiewicz merged commit cee6a96 into master Aug 26, 2026
2 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@slachiewicz
slachiewicz deleted the feature/maven-4.1-try-with-resources branch August 26, 2026 16:21
@github-actions github-actions Bot assigned slachiewicz Aug 26, 2026
@github-actions github-actions Bot added this to the 4.1.0 milestone Aug 26, 2026
@slachiewicz slachiewicz added maintenance and removed bug Something isn't working labels Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gnodet gnodet gnodet approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@slachiewicz slachiewicz

Labels

maintenance

Projects

None yet

Milestone

4.2.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@slachiewicz @gnodet
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.