Skip to content

[maven-4.0.x] BuildPlanExecutor: thread pool leaked on constructor exception #12599

Description

@elharo

BuildPlanExecutor: Thread pool leaked on constructor exception

Found in: maven-4.0.x branch
File: impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutor.java (line 214)
Severity: Medium

Description

The BuildContext constructor creates a thread pool and then calls buildInitialPlan():

BuildContext(MavenSession session, ReactorContext reactorContext, List<TaskSegment> taskSegments) {
    ...
    this.executor = new PhasingExecutor(Executors.newFixedThreadPool(threads, new BuildThreadFactory()));
    this.plan = buildInitialPlan(taskSegments);
}

buildInitialPlan() is called inside the constructor, before the try-with-resources in execute() begins. If buildInitialPlan() throws (e.g., PluginNotFoundException, LifecyclePhaseNotFoundException), the BuildContext constructor throws and close() is never called (the object was never fully constructed), leaving the thread pool running indefinitely as a resource leak.

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