elharo opened a new issue, #12609:
URL: https://github.com/apache/maven/issues/12609
# 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`:
```java
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()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]