Skip to content

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions