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

gnodet 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 2b171a8a7d Report a clear error for an unparsable extensions.xml 
(#13957)
2b171a8a7d is described below

commit 2b171a8a7d33696ea5405740e1f3b88e051a3b17
Author: Guillaume Nodet <[email protected]>
AuthorDate: Thu Nov 12 22:49:43 2026 +0100

    Report a clear error for an unparsable extensions.xml (#13957)
    
    * [MNG-8369] Report a clear error for an unparsable extensions.xml
    
    Port of #13947 (maven-3.10.x) to the `master` 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
    
    * Report a clear error for an unparsable extensions.xml
    
    Port of #13947 (maven-3.10.x) to the `master` 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 0ff31d7683..bf18a3e739 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
@@ -955,8 +955,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)) {
@@ -964,6 +963,9 @@ private List<CoreExtension> 
readCoreExtensionsDescriptor(String extensionsFile)
                     return new CoreExtensionsStaxReader()
                             .read(is, true, InputSource.of(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 63ed9628f3..c1e1baf817 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
@@ -148,6 +148,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();

Reply via email to