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().
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 aBuilderwithout settinguserPropertiesorsystemProperties, leaving them asnull:build()passes them to theImplconstructor which callsMap.copyOf(null)on each, resulting in aNullPointerException. ThenewBuilder()static factory is a public API that leads to an NPE whenbuild()is called without setting properties. Fix by initializing fields toMap.of().