diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/PathSource.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/PathSource.java index e7b39ac1bef5..4029179f3fd4 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/PathSource.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/PathSource.java @@ -72,6 +72,10 @@ public ModelSource resolve(ModelLocator locator, String relative) { @Override public boolean equals(Object o) { + if (o == null) { + return false; + } + return this == o || o.getClass() == getClass() && Objects.equals(path, ((PathSource) o).path); } diff --git a/api/maven-api-core/src/test/java/org/apache/maven/api/services/PathSourceTest.java b/api/maven-api-core/src/test/java/org/apache/maven/api/services/PathSourceTest.java new file mode 100644 index 000000000000..19a5efe79a6f --- /dev/null +++ b/api/maven-api-core/src/test/java/org/apache/maven/api/services/PathSourceTest.java @@ -0,0 +1,34 @@ +/* + * 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.services; + +import java.nio.file.Paths; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +class PathSourceTest { + + @Test + void testEquals() { + PathSource source = new PathSource(Paths.get("/tmp")); + assertFalse(source.equals(null)); + } +}