From c5bd8ae2871d0d06271354cdbc03d69824db80ed Mon Sep 17 00:00:00 2001 From: Silva Dev BR <116388885+Will-thom@users.noreply.github.com> Date: Sat, 13 Jun 2026 06:53:15 -0300 Subject: [PATCH 1/2] Handle missing package metadata in model ids (#12146) --- .../plugin/DefaultReportingConverter.java | 9 ++++-- .../superpom/DefaultSuperPomProvider.java | 9 ++++-- .../plugin/DefaultReportingConverterTest.java | 31 +++++++++++++++++++ .../superpom/DefaultSuperPomProviderTest.java | 31 +++++++++++++++++++ .../impl/DefaultLifecycleRegistry.java | 7 ++++- .../impl/DefaultLifecycleRegistryTest.java | 31 +++++++++++++++++++ .../maven/impl/DefaultSuperPomProvider.java | 9 ++++-- .../impl/DefaultSuperPomProviderTest.java | 31 +++++++++++++++++++ 8 files changed, 151 insertions(+), 7 deletions(-) create mode 100644 compat/maven-model-builder/src/test/java/org/apache/maven/model/plugin/DefaultReportingConverterTest.java create mode 100644 compat/maven-model-builder/src/test/java/org/apache/maven/model/superpom/DefaultSuperPomProviderTest.java create mode 100644 impl/maven-core/src/test/java/org/apache/maven/internal/impl/DefaultLifecycleRegistryTest.java create mode 100644 impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSuperPomProviderTest.java 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 e4bc0df16073..ee49ef7596bc 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 3c09c19af5cd..23db9d060d70 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 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 000000000000..6bb79212a475 --- /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 000000000000..78a834a77711 --- /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 d9a7058df089..ed9fdf1998ab 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 providers) { } } + static String getImplementationVersion(Class clazz) { + Package packageInfo = clazz.getPackage(); + return packageInfo != null ? packageInfo.getImplementationVersion() : null; + } + @Override public Iterator 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 000000000000..a154a23c9dc7 --- /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 bfc199fe63b5..1ca1382d98eb 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 000000000000..547e5d285da6 --- /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)); + } +} From 4afcff67e32e75a2c227f939d452e59fb0a9bc7c Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Sat, 13 Jun 2026 11:47:25 +0000 Subject: [PATCH 2/2] Retrigger CI