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 6fcfcc4623 Handle missing package metadata in model ids (#12257)
6fcfcc4623 is described below

commit 6fcfcc462300cccc879fff0141539d81743bedaf
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sun Jun 14 00:20:20 2026 +0200

    Handle missing package metadata in model ids (#12257)
    
    * Handle missing package metadata in model ids (#12146)
    
    * Retrigger CI
    
    ---------
    
    Co-authored-by: Silva Dev BR <[email protected]>
---
 .../model/plugin/DefaultReportingConverter.java    |  9 +++++--
 .../model/superpom/DefaultSuperPomProvider.java    |  9 +++++--
 .../plugin/DefaultReportingConverterTest.java      | 31 ++++++++++++++++++++++
 .../superpom/DefaultSuperPomProviderTest.java      | 31 ++++++++++++++++++++++
 .../internal/impl/DefaultLifecycleRegistry.java    |  7 ++++-
 .../impl/DefaultLifecycleRegistryTest.java         | 31 ++++++++++++++++++++++
 .../apache/maven/impl/DefaultSuperPomProvider.java |  9 +++++--
 .../maven/impl/DefaultSuperPomProviderTest.java    | 31 ++++++++++++++++++++++
 8 files changed, 151 insertions(+), 7 deletions(-)

diff --git 
a/compat/maven-model-builder/src/main/java/org/apache/maven/model/plugin/DefaultReportingConverter.java
 
b/compat/maven-model-builder/src/main/java/org/apache/maven/model/plugin/DefaultReportingConverter.java
index e4bc0df160..ee49ef7596 100644
--- 
a/compat/maven-model-builder/src/main/java/org/apache/maven/model/plugin/DefaultReportingConverter.java
+++ 
b/compat/maven-model-builder/src/main/java/org/apache/maven/model/plugin/DefaultReportingConverter.java
@@ -51,14 +51,19 @@ public class DefaultReportingConverter implements 
ReportingConverter {
     private final InputLocation location;
 
     {
-        String modelId = "org.apache.maven:maven-model-builder:"
-                + this.getClass().getPackage().getImplementationVersion() + 
":reporting-converter";
+        String modelId =
+                "org.apache.maven:maven-model-builder:" + 
getImplementationVersion(getClass()) + ":reporting-converter";
         InputSource inputSource = new InputSource();
         inputSource.setModelId(modelId);
         location = new InputLocation(-1, -1, inputSource);
         location.setLocation(0, location);
     }
 
+    static String getImplementationVersion(Class<?> clazz) {
+        Package packageInfo = clazz.getPackage();
+        return packageInfo != null ? packageInfo.getImplementationVersion() : 
null;
+    }
+
     @Override
     public void convertReporting(Model model, ModelBuildingRequest request, 
ModelProblemCollector problems) {
         Reporting reporting = model.getReporting();
diff --git 
a/compat/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java
 
b/compat/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java
index 3c09c19af5..23db9d060d 100644
--- 
a/compat/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java
+++ 
b/compat/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java
@@ -70,8 +70,8 @@ public Model getSuperModel(String version) {
                 Map<String, Object> options = new HashMap<>();
                 options.put("xml:4.0.0", "xml:4.0.0");
 
-                String modelId = "org.apache.maven:maven-model-builder:"
-                        + 
this.getClass().getPackage().getImplementationVersion() + ":super-pom";
+                String modelId =
+                        "org.apache.maven:maven-model-builder:" + 
getImplementationVersion(getClass()) + ":super-pom";
                 InputSource inputSource = new InputSource();
                 inputSource.setModelId(modelId);
                 
inputSource.setLocation(getClass().getResource(resource).toExternalForm());
@@ -88,4 +88,9 @@ public Model getSuperModel(String version) {
 
         return superModel;
     }
+
+    static String getImplementationVersion(Class<?> clazz) {
+        Package packageInfo = clazz.getPackage();
+        return packageInfo != null ? packageInfo.getImplementationVersion() : 
null;
+    }
 }
diff --git 
a/compat/maven-model-builder/src/test/java/org/apache/maven/model/plugin/DefaultReportingConverterTest.java
 
b/compat/maven-model-builder/src/test/java/org/apache/maven/model/plugin/DefaultReportingConverterTest.java
new file mode 100644
index 0000000000..6bb79212a4
--- /dev/null
+++ 
b/compat/maven-model-builder/src/test/java/org/apache/maven/model/plugin/DefaultReportingConverterTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.model.plugin;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class DefaultReportingConverterTest {
+
+    @Test
+    void returnsNullImplementationVersionWhenClassHasNoPackage() {
+        
assertNull(DefaultReportingConverter.getImplementationVersion(int.class));
+    }
+}
diff --git 
a/compat/maven-model-builder/src/test/java/org/apache/maven/model/superpom/DefaultSuperPomProviderTest.java
 
b/compat/maven-model-builder/src/test/java/org/apache/maven/model/superpom/DefaultSuperPomProviderTest.java
new file mode 100644
index 0000000000..78a834a777
--- /dev/null
+++ 
b/compat/maven-model-builder/src/test/java/org/apache/maven/model/superpom/DefaultSuperPomProviderTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.model.superpom;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class DefaultSuperPomProviderTest {
+
+    @Test
+    void returnsNullImplementationVersionWhenClassHasNoPackage() {
+        
assertNull(DefaultSuperPomProvider.getImplementationVersion(int.class));
+    }
+}
diff --git 
a/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java
 
b/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java
index d9a7058df0..ed9fdf1998 100644
--- 
a/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java
+++ 
b/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java
@@ -88,7 +88,7 @@ public class DefaultLifecycleRegistry implements 
LifecycleRegistry {
     private static final String MAVEN_PLUGINS = "org.apache.maven.plugins:";
 
     public static final String DEFAULT_LIFECYCLE_MODELID = 
"org.apache.maven:maven-core:"
-            + 
DefaultLifecycleRegistry.class.getPackage().getImplementationVersion()
+            + getImplementationVersion(DefaultLifecycleRegistry.class)
             + ":default-lifecycle-bindings";
 
     public static final InputLocation DEFAULT_LIFECYCLE_INPUT_LOCATION =
@@ -122,6 +122,11 @@ public DefaultLifecycleRegistry(List<LifecycleProvider> 
providers) {
         }
     }
 
+    static String getImplementationVersion(Class<?> clazz) {
+        Package packageInfo = clazz.getPackage();
+        return packageInfo != null ? packageInfo.getImplementationVersion() : 
null;
+    }
+
     @Override
     public Iterator<Lifecycle> iterator() {
         return stream().toList().iterator();
diff --git 
a/impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultLifecycleRegistryTest.java
 
b/impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultLifecycleRegistryTest.java
new file mode 100644
index 0000000000..a154a23c9d
--- /dev/null
+++ 
b/impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultLifecycleRegistryTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.internal.impl;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class DefaultLifecycleRegistryTest {
+
+    @Test
+    void returnsNullImplementationVersionWhenClassHasNoPackage() {
+        
assertNull(DefaultLifecycleRegistry.getImplementationVersion(int.class));
+    }
+}
diff --git 
a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSuperPomProvider.java
 
b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSuperPomProvider.java
index bfc199fe63..1ca1382d98 100644
--- 
a/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSuperPomProvider.java
+++ 
b/impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSuperPomProvider.java
@@ -62,8 +62,8 @@ private Model readModel(String version, String v) {
                     + ", please verify the integrity of your Maven 
installation");
         }
         try (InputStream is = url.openStream()) {
-            String modelId = "org.apache.maven:maven-api-impl:"
-                    + this.getClass().getPackage().getImplementationVersion() 
+ ":super-pom-" + version;
+            String modelId =
+                    "org.apache.maven:maven-api-impl:" + 
getImplementationVersion(getClass()) + ":super-pom-" + version;
             return modelProcessor.read(XmlReaderRequest.builder()
                     .modelId(modelId)
                     .location(url.toExternalForm())
@@ -77,4 +77,9 @@ private Model readModel(String version, String v) {
                     e);
         }
     }
+
+    static String getImplementationVersion(Class<?> clazz) {
+        Package packageInfo = clazz.getPackage();
+        return packageInfo != null ? packageInfo.getImplementationVersion() : 
null;
+    }
 }
diff --git 
a/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSuperPomProviderTest.java
 
b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSuperPomProviderTest.java
new file mode 100644
index 0000000000..547e5d285d
--- /dev/null
+++ 
b/impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSuperPomProviderTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.impl;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+class DefaultSuperPomProviderTest {
+
+    @Test
+    void returnsNullImplementationVersionWhenClassHasNoPackage() {
+        
assertNull(DefaultSuperPomProvider.getImplementationVersion(int.class));
+    }
+}

Reply via email to