Skip to content

[maven-4.0.x] ProtoSession.Builder.newBuilder() NPE on unset property maps #12609

Description

@elharo

ProtoSession.Builder.newBuilder() NPE on unset property maps

Found in: maven-4.0.x branch
File: api/maven-api-core/src/main/java/org/apache/maven/api/ProtoSession.java (inner class Builder, lines ~110-112, 147-148)
Severity: Low

Description

The newBuilder() factory method creates a Builder without setting userProperties or systemProperties, leaving them as null:

static Builder newBuilder() {
    return new Builder().withStartTime(MonotonicClock.now());
}

// Builder fields are not initialized:
private Map<String, String> userProperties;     // null
private Map<String, String> systemProperties;   // null

public ProtoSession build() {
    return new Impl(userProperties, systemProperties, startTime, topDirectory, rootDirectory);
    // Map.copyOf(null) throws NPE
}

build() passes them to the Impl constructor which calls Map.copyOf(null) on each, resulting in a NullPointerException. The newBuilder() static factory is a public API that leads to an NPE when build() is called without setting properties. Fix by initializing fields to Map.of().

Metadata

Metadata

Assignees

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