You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/09/15 23:32:52 UTC

(maven) branch maven-4.0.x updated: Normalize lazy StAX parse failures in MavenXpp3Reader (#13117) (#13149)

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 42dc31c72c Normalize lazy StAX parse failures in MavenXpp3Reader (#13117) (#13149)
42dc31c72c is described below

commit 42dc31c72cd1f96c40cdc1227fb52307643c9c15
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Wed Sep 16 01:32:46 2026 +0200

    Normalize lazy StAX parse failures in MavenXpp3Reader (#13117) (#13149)
    
    * Normalize lazy StAX parse failures in MavenXpp3Reader
    
    Woodstox can defer malformed character-reference errors until text access and wrap the XMLStreamException in a runtime exception. MavenXpp3Reader currently translates only directly thrown XMLStreamException values, allowing the lazy wrapper to escape the declared XmlPullParserException contract.
    
    Translate runtime exceptions whose cause is an XMLStreamException while preserving unrelated runtime failures. Add regression coverage for both Reader and InputStream paths.
    
    
    
    * Extend lazy StAX exception fix to SettingsXpp3Reader, MetadataXpp3Reader, MavenToolchainsXpp3Reader
    
    Same WstxLazyException escape path exists in all four compat readers.
    Also strengthen the test to assert the cause is an XMLStreamException.
    
    * Extend RuntimeException guard to XMLStreamReader overloads in Settings/MetadataXpp3Reader
    
    ---------
    
    Signed-off-by: Robert McConnell <ro...@mcc0nnell.org>
    Co-authored-by: Robert McConnell <ro...@mcc0nnell.org>
---
 .../maven/model/io/xpp3/MavenXpp3Reader.java       | 10 +++++
 .../maven/model/io/xpp3/MavenXpp3ReaderTest.java   | 49 ++++++++++++++++++++++
 .../metadata/io/xpp3/MetadataXpp3Reader.java       | 25 +++++++++++
 .../maven/settings/io/xpp3/SettingsXpp3Reader.java | 25 +++++++++++
 .../model/io/xpp3/MavenToolchainsXpp3Reader.java   |  5 +++
 5 files changed, 114 insertions(+)

diff --git a/compat/maven-model/src/main/java/org/apache/maven/model/io/xpp3/MavenXpp3Reader.java b/compat/maven-model/src/main/java/org/apache/maven/model/io/xpp3/MavenXpp3Reader.java
index 9d47e7dd13..edfd2cb53c 100644
--- a/compat/maven-model/src/main/java/org/apache/maven/model/io/xpp3/MavenXpp3Reader.java
+++ b/compat/maven-model/src/main/java/org/apache/maven/model/io/xpp3/MavenXpp3Reader.java
@@ -75,6 +75,11 @@ protected Model read(Reader reader, boolean strict, InputSource source) throws I
             return new Model(model);
         } catch (XMLStreamException e) {
             throw new XmlPullParserException(e.getMessage(), null, e);
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof XMLStreamException cause) {
+                throw new XmlPullParserException(cause.getMessage(), null, cause);
+            }
+            throw e;
         }
     }
 
@@ -111,6 +116,11 @@ protected Model read(InputStream is, boolean strict, InputSource source)
             return new Model(model);
         } catch (XMLStreamException e) {
             throw new XmlPullParserException(e.getMessage(), null, e);
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof XMLStreamException cause) {
+                throw new XmlPullParserException(cause.getMessage(), null, cause);
+            }
+            throw e;
         }
     }
 
diff --git a/compat/maven-model/src/test/java/org/apache/maven/model/io/xpp3/MavenXpp3ReaderTest.java b/compat/maven-model/src/test/java/org/apache/maven/model/io/xpp3/MavenXpp3ReaderTest.java
new file mode 100644
index 0000000000..186dc2b7bd
--- /dev/null
+++ b/compat/maven-model/src/test/java/org/apache/maven/model/io/xpp3/MavenXpp3ReaderTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.io.xpp3;
+
+import javax.xml.stream.XMLStreamException;
+
+import java.io.ByteArrayInputStream;
+import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
+
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class MavenXpp3ReaderTest {
+    private static final String MALFORMED_XML = "<project><description>p&#9a9;</description></project>";
+
+    @Test
+    void malformedLazyXmlFailureIsReportedAsXmlPullParserException() {
+        MavenXpp3Reader reader = new MavenXpp3Reader();
+
+        XmlPullParserException readerEx =
+                assertThrows(XmlPullParserException.class, () -> reader.read(new StringReader(MALFORMED_XML)));
+        assertInstanceOf(XMLStreamException.class, readerEx.getCause(), "cause should be the XMLStreamException");
+
+        XmlPullParserException streamEx = assertThrows(
+                XmlPullParserException.class,
+                () -> reader.read(new ByteArrayInputStream(MALFORMED_XML.getBytes(StandardCharsets.UTF_8))));
+        assertInstanceOf(XMLStreamException.class, streamEx.getCause(), "cause should be the XMLStreamException");
+    }
+}
diff --git a/compat/maven-repository-metadata/src/main/java/org/apache/maven/artifact/repository/metadata/io/xpp3/MetadataXpp3Reader.java b/compat/maven-repository-metadata/src/main/java/org/apache/maven/artifact/repository/metadata/io/xpp3/MetadataXpp3Reader.java
index 029fa9964b..2ca50b517a 100644
--- a/compat/maven-repository-metadata/src/main/java/org/apache/maven/artifact/repository/metadata/io/xpp3/MetadataXpp3Reader.java
+++ b/compat/maven-repository-metadata/src/main/java/org/apache/maven/artifact/repository/metadata/io/xpp3/MetadataXpp3Reader.java
@@ -88,6 +88,11 @@ public Metadata read(Reader reader, boolean strict) throws IOException, XmlPullP
             return new Metadata(delegate.read(reader, strict));
         } catch (XMLStreamException e) {
             throw new XmlPullParserException(e.getMessage(), null, e);
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof XMLStreamException cause) {
+                throw new XmlPullParserException(cause.getMessage(), null, cause);
+            }
+            throw e;
         }
     }
 
@@ -105,6 +110,11 @@ public Metadata read(Reader reader) throws IOException, XmlPullParserException {
             return new Metadata(delegate.read(reader));
         } catch (XMLStreamException e) {
             throw new XmlPullParserException(e.getMessage(), null, e);
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof XMLStreamException cause) {
+                throw new XmlPullParserException(cause.getMessage(), null, cause);
+            }
+            throw e;
         }
     }
 
@@ -123,6 +133,11 @@ public Metadata read(InputStream in, boolean strict) throws IOException, XmlPull
             return new Metadata(delegate.read(in, strict));
         } catch (XMLStreamException e) {
             throw new XmlPullParserException(e.getMessage(), null, e);
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof XMLStreamException cause) {
+                throw new XmlPullParserException(cause.getMessage(), null, cause);
+            }
+            throw e;
         }
     }
 
@@ -140,6 +155,11 @@ public Metadata read(InputStream in) throws IOException, XmlPullParserException
             return new Metadata(delegate.read(in));
         } catch (XMLStreamException e) {
             throw new XmlPullParserException(e.getMessage(), null, e);
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof XMLStreamException cause) {
+                throw new XmlPullParserException(cause.getMessage(), null, cause);
+            }
+            throw e;
         }
     }
 
@@ -158,6 +178,11 @@ public Metadata read(XMLStreamReader parser, boolean strict) throws IOException,
             return new Metadata(delegate.read(parser, strict));
         } catch (XMLStreamException e) {
             throw new XmlPullParserException(e.getMessage(), null, e);
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof XMLStreamException cause) {
+                throw new XmlPullParserException(cause.getMessage(), null, cause);
+            }
+            throw e;
         }
     }
 
diff --git a/compat/maven-settings/src/main/java/org/apache/maven/settings/io/xpp3/SettingsXpp3Reader.java b/compat/maven-settings/src/main/java/org/apache/maven/settings/io/xpp3/SettingsXpp3Reader.java
index 7ff965afa8..fd44711531 100644
--- a/compat/maven-settings/src/main/java/org/apache/maven/settings/io/xpp3/SettingsXpp3Reader.java
+++ b/compat/maven-settings/src/main/java/org/apache/maven/settings/io/xpp3/SettingsXpp3Reader.java
@@ -69,6 +69,11 @@ public Settings read(Reader reader, boolean strict) throws IOException, XmlPullP
             return new Settings(delegate.read(reader, strict, null));
         } catch (XMLStreamException e) {
             throw new XmlPullParserException(e.getMessage(), null, e);
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof XMLStreamException cause) {
+                throw new XmlPullParserException(cause.getMessage(), null, cause);
+            }
+            throw e;
         }
     }
 
@@ -77,6 +82,11 @@ public Settings read(Reader reader) throws IOException, XmlPullParserException {
             return new Settings(delegate.read(reader));
         } catch (XMLStreamException e) {
             throw new XmlPullParserException(e.getMessage(), null, e);
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof XMLStreamException cause) {
+                throw new XmlPullParserException(cause.getMessage(), null, cause);
+            }
+            throw e;
         }
     }
 
@@ -85,6 +95,11 @@ public Settings read(InputStream in, boolean strict) throws IOException, XmlPull
             return new Settings(delegate.read(in, strict, null));
         } catch (XMLStreamException e) {
             throw new XmlPullParserException(e.getMessage(), null, e);
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof XMLStreamException cause) {
+                throw new XmlPullParserException(cause.getMessage(), null, cause);
+            }
+            throw e;
         }
     }
 
@@ -93,6 +108,11 @@ public Settings read(InputStream in) throws IOException, XmlPullParserException
             return new Settings(delegate.read(in));
         } catch (XMLStreamException e) {
             throw new XmlPullParserException(e.getMessage(), null, e);
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof XMLStreamException cause) {
+                throw new XmlPullParserException(cause.getMessage(), null, cause);
+            }
+            throw e;
         }
     }
 
@@ -101,6 +121,11 @@ public Settings read(XMLStreamReader parser, boolean strict) throws IOException,
             return new Settings(delegate.read(parser, strict, null));
         } catch (XMLStreamException e) {
             throw new XmlPullParserException(e.getMessage(), null, e);
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof XMLStreamException cause) {
+                throw new XmlPullParserException(cause.getMessage(), null, cause);
+            }
+            throw e;
         }
     }
 
diff --git a/compat/maven-toolchain-model/src/main/java/org/apache/maven/toolchain/model/io/xpp3/MavenToolchainsXpp3Reader.java b/compat/maven-toolchain-model/src/main/java/org/apache/maven/toolchain/model/io/xpp3/MavenToolchainsXpp3Reader.java
index bbee063d9d..56ac40c8cb 100644
--- a/compat/maven-toolchain-model/src/main/java/org/apache/maven/toolchain/model/io/xpp3/MavenToolchainsXpp3Reader.java
+++ b/compat/maven-toolchain-model/src/main/java/org/apache/maven/toolchain/model/io/xpp3/MavenToolchainsXpp3Reader.java
@@ -95,6 +95,11 @@ public PersistedToolchains read(Reader reader, boolean strict) throws IOExceptio
             return new PersistedToolchains(delegate.read(reader, strict, null));
         } catch (XMLStreamException e) {
             throw new XmlPullParserException(e.getMessage(), null, e);
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof XMLStreamException cause) {
+                throw new XmlPullParserException(cause.getMessage(), null, cause);
+            }
+            throw e;
         }
     }