This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch maven-4.0.x
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/maven-4.0.x by this push:
     new 763898b8ee [maven-4.0.x] Backport bug fixes from #11741 and #11733 
(#12144)
763898b8ee is described below

commit 763898b8ee20e1ba847dd291544bf4babbd80072
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sat May 23 08:52:37 2026 +0200

    [maven-4.0.x] Backport bug fixes from #11741 and #11733 (#12144)
    
    * Fix gh-11740: Add missing null check in validateProfileId() (#11741)
    
    The validateProfileId() method was missing a null check before calling
    validProfileIds.contains(id). Since validProfileIds uses
    ConcurrentHashMap.newKeySet() which doesn't allow null keys, a null
    profile ID would cause a NullPointerException instead of a proper
    validation error.
    
    This makes validateProfileId() consistent with validateCoordinateId()
    which already has the null check.
    
    Fixes #11740
    
    Co-authored-by: Claude Opus 4.6 <[email protected]>
    
    * fix: error == null to error != null in isError (#11733)
    
    * fix: error == null to error != null in isError
    
    * feat: add regresion test
    
    ---------
    
    Co-authored-by: Abhishek Chauhan <[email protected]>
    Co-authored-by: Claude Opus 4.6 <[email protected]>
    Co-authored-by: cui <[email protected]>
---
 .../repository/metadata/ArtifactMetadata.java      |  2 +-
 .../repository/metadata/ArtifactMetadataTest.java  | 68 ++++++++++++++++++++++
 .../maven/impl/model/DefaultModelValidator.java    |  2 +-
 3 files changed, 70 insertions(+), 2 deletions(-)

diff --git 
a/compat/maven-compat/src/main/java/org/apache/maven/repository/metadata/ArtifactMetadata.java
 
b/compat/maven-compat/src/main/java/org/apache/maven/repository/metadata/ArtifactMetadata.java
index a808e2be8c..c690cebf9a 100644
--- 
a/compat/maven-compat/src/main/java/org/apache/maven/repository/metadata/ArtifactMetadata.java
+++ 
b/compat/maven-compat/src/main/java/org/apache/maven/repository/metadata/ArtifactMetadata.java
@@ -301,7 +301,7 @@ public void setError(String error) {
     }
 
     public boolean isError() {
-        return error == null;
+        return error != null;
     }
 
     public String getDependencyConflictId() {
diff --git 
a/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/ArtifactMetadataTest.java
 
b/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/ArtifactMetadataTest.java
new file mode 100644
index 0000000000..c319730133
--- /dev/null
+++ 
b/compat/maven-compat/src/test/java/org/apache/maven/repository/metadata/ArtifactMetadataTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.repository.metadata;
+
+import org.apache.maven.artifact.ArtifactScopeEnum;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Regression test for {@link ArtifactMetadata#isError()}.
+ * Verifies that isError() returns true when error is set, false when error is 
null.
+ */
+@Deprecated
+class ArtifactMetadataTest {
+
+    @Test
+    void isErrorReturnsFalseWhenErrorIsNull() {
+        ArtifactMetadata metadata = new ArtifactMetadata("g:a:1.0");
+        assertFalse(metadata.isError());
+    }
+
+    @Test
+    void isErrorReturnsTrueWhenErrorIsSet() {
+        ArtifactMetadata metadata = new ArtifactMetadata("g:a:1.0");
+        metadata.setError("Something went wrong");
+        assertTrue(metadata.isError());
+    }
+
+    @Test
+    void isErrorReturnsFalseAfterErrorIsCleared() {
+        ArtifactMetadata metadata = new ArtifactMetadata("g:a:1.0");
+        metadata.setError("Something went wrong");
+        metadata.setError(null);
+        assertFalse(metadata.isError());
+    }
+
+    @Test
+    void isErrorReturnsTrueWhenConstructedWithError() {
+        ArtifactMetadata metadata = new ArtifactMetadata(
+                "g", "a", "1.0", "jar", ArtifactScopeEnum.DEFAULT_SCOPE, null, 
null, null, false, "Resolution failed");
+        assertTrue(metadata.isError());
+    }
+
+    @Test
+    void isErrorReturnsFalseWhenConstructedWithoutError() {
+        ArtifactMetadata metadata = new ArtifactMetadata(
+                "g", "a", "1.0", "jar", ArtifactScopeEnum.DEFAULT_SCOPE, null, 
null, null, true, null);
+        assertFalse(metadata.isError());
+    }
+}
diff --git 
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java
 
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java
index 44b3353336..47cd0efefe 100644
--- 
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java
+++ 
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java
@@ -1705,7 +1705,7 @@ private boolean validateProfileId(
             String id,
             @Nullable SourceHint sourceHint,
             InputLocationTracker tracker) {
-        if (validProfileIds.contains(id)) {
+        if (id != null && validProfileIds.contains(id)) {
             return true;
         }
         if (!validateStringNotEmpty(prefix, fieldName, problems, severity, 
version, id, sourceHint, tracker)) {

Reply via email to