Skip to content

[maven-4.0.x] DefaultMaven: session scope leak on constructor exception #12607

Closed

Description

@elharo

DefaultMaven: Session scope leak on constructor exception

Found in: maven-4.0.x branch
File: impl/maven-core/src/main/java/org/apache/maven/DefaultMaven.java (lines 213-216)
Severity: Medium

Description

sessionScope.enter() is called outside the try-finally block:

sessionScope.enter();
MavenChainedWorkspaceReader chainedWorkspaceReader =
        new MavenChainedWorkspaceReader(request.getWorkspaceReader(), ideWorkspaceReader);
try (CloseableSession closeableSession = ...) {
    ...
} finally {
    sessionScope.exit();
}

If the constructor new MavenChainedWorkspaceReader(...) at lines 214-215 throws any exception, the sessionScope.exit() in the finally block will never execute. This leaks the session scope's thread-local state. The ideWorkspaceReader parameter is @Nullable, and the constructor delegates to setReaders() which could throw.

Activity

  1. added
    bug
    on Jul 29, 2026
  2. added this to the 4.0.0-rc-7 milestone on Aug 23, 2026
  3. added a commit that references this issue on Aug 24, 2026
    4e0c691
  4. added a commit that references this issue on Aug 28, 2026
    5ae676d
  5. added a commit that references this issue on Aug 28, 2026
    5753424
  6. added a commit that references this issue on Aug 30, 2026
    850d3de
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmvn4

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions