diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/ProtoSession.java b/api/maven-api-core/src/main/java/org/apache/maven/api/ProtoSession.java index 41300d074e63..cacf6b8a8121 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/ProtoSession.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/ProtoSession.java @@ -116,8 +116,8 @@ static Builder newBuilder() { } class Builder { - private Map userProperties; - private Map systemProperties; + private Map userProperties = Map.of(); + private Map systemProperties = Map.of(); private Instant startTime; private Path topDirectory; private Path rootDirectory; diff --git a/api/maven-api-core/src/test/java/org/apache/maven/api/ProtoSessionTest.java b/api/maven-api-core/src/test/java/org/apache/maven/api/ProtoSessionTest.java new file mode 100644 index 000000000000..d186402edd5a --- /dev/null +++ b/api/maven-api-core/src/test/java/org/apache/maven/api/ProtoSessionTest.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.api; + +import java.nio.file.Paths; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class ProtoSessionTest { + + @Test + void testNewBuilderWithUnsetPropertyMaps() { + ProtoSession session = ProtoSession.newBuilder() + .withTopDirectory(Paths.get(".")) + .withRootDirectory(Paths.get(".")) + .build(); + assertNotNull(session); + assertNotNull(session.getUserProperties()); + assertTrue(session.getUserProperties().isEmpty(), "User properties should default to empty"); + assertNotNull(session.getSystemProperties()); + assertTrue(session.getSystemProperties().isEmpty(), "System properties should default to empty"); + } +}