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 6e63ace67b Report a clear error for an unparsable extensions.xml
(#13956)
6e63ace67b is described below
commit 6e63ace67b379237167d972e0fca109c496cfbf1
Author: Guillaume Nodet <[email protected]>
AuthorDate: Thu Nov 12 22:48:37 2026 +0100
Report a clear error for an unparsable extensions.xml (#13956)
Port of #13947 (maven-3.10.x) to the `maven-4.0.x` compat layer.
readCoreExtensionsDescriptor() let any failure from the XML parser escape
as-is, so an empty or otherwise malformed .mvn/extensions.xml surfaced as
a bare EOFException or XMLStreamException with a full stack trace instead
of a message naming the problem file.
Wrap the parse failure in an IOException that names the extensions file,
keeping the original exception as the cause so -e still shows the full
chain.
Fixes #10258
---
.../src/main/java/org/apache/maven/cli/MavenCli.java | 6 ++++--
.../src/test/java/org/apache/maven/cli/MavenCliTest.java | 15 +++++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git
a/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
b/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index 88ceec6e02..3e3d3a4e84 100644
--- a/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -906,8 +906,7 @@ protected void configure() {
}
}
- private List<CoreExtension> readCoreExtensionsDescriptor(String
extensionsFile)
- throws IOException, XMLStreamException {
+ List<CoreExtension> readCoreExtensionsDescriptor(String extensionsFile)
throws IOException {
if (extensionsFile != null) {
Path extensionsPath = Path.of(extensionsFile);
if (Files.exists(extensionsPath)) {
@@ -915,6 +914,9 @@ private List<CoreExtension>
readCoreExtensionsDescriptor(String extensionsFile)
return new CoreExtensionsStaxReader()
.read(is, true, new InputSource(extensionsFile))
.getExtensions();
+ } catch (IOException | XMLStreamException e) {
+ throw new IOException(
+ "Unable to parse core extensions descriptor " +
extensionsFile + ": " + e.getMessage(), e);
}
}
}
diff --git
a/compat/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
b/compat/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
index 04d8ee2c9e..799d6becbb 100644
--- a/compat/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
+++ b/compat/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
@@ -137,6 +137,21 @@ public void testReadPasswordRejectsMissingPassword() {
null, new
ByteArrayInputStream("\n".getBytes(StandardCharsets.UTF_8)), "Password: "));
}
+ /**
+ * An empty or otherwise unparsable extensions descriptor should fail with
a message naming the file, not a bare
+ * {@code EOFException} or {@code XMLStreamException} from the XML parser
(MNG-8369).
+ */
+ @Test
+ public void testReadCoreExtensionsDescriptorRejectsUnparsableFile(@TempDir
Path tempDir) throws Exception {
+ Path extensionsFile = tempDir.resolve("extensions.xml");
+ Files.createFile(extensionsFile);
+
+ IOException e =
+ assertThrows(IOException.class, () ->
cli.readCoreExtensionsDescriptor(extensionsFile.toString()));
+
+ assertTrue(e.getMessage().contains(extensionsFile.toString()),
e.getMessage());
+ }
+
@Test
void testPerformProfileActivation() throws ParseException {
final CommandLineParser parser = new DefaultParser();