You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2025/01/08 15:51:55 UTC
(maven) branch master updated: Fix comparisons against null in PathSource.equals (#2026)
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new 99452bb868 Fix comparisons against null in PathSource.equals (#2026)
99452bb868 is described below
commit 99452bb86846684e1ad636023268bd4f9b17dfac
Author: Elliotte Rusty Harold <el...@users.noreply.github.com>
AuthorDate: Wed Jan 8 15:51:49 2025 +0000
Fix comparisons against null in PathSource.equals (#2026)
* Fix comparisons against null
---
.../org/apache/maven/api/services/PathSource.java | 4 +++
.../apache/maven/api/services/PathSourceTest.java | 34 ++++++++++++++++++++++
2 files changed, 38 insertions(+)
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 e7b39ac1be..4029179f3f 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 @@ class PathSource implements ModelSource {
@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 0000000000..19a5efe79a
--- /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));
+ }
+}