gnodet-bot commented on code in PR #13117:
URL: https://github.com/apache/maven/pull/13117#discussion_r4010428766


##########
compat/maven-model/src/test/java/org/apache/maven/model/io/xpp3/MavenXpp3ReaderTest.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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 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.assertThrows;
+
+class MavenXpp3ReaderTest {
+    private static final String MALFORMED_XML = 
"<project><description>p&#9a9;</description></project>";
+
+    @Test
+    void malformedLazyXmlFailureIsReportedAsXmlPullParserException() {
+        MavenXpp3Reader reader = new MavenXpp3Reader();
+
+        assertThrows(XmlPullParserException.class, () -> reader.read(new 
StringReader(MALFORMED_XML)));
+        assertThrows(
+                XmlPullParserException.class,
+                () -> reader.read(new 
ByteArrayInputStream(MALFORMED_XML.getBytes(StandardCharsets.UTF_8))));
+    }

Review Comment:
   ⚠️ **Missing cause assertion** — the test validates that _a_ 
`XmlPullParserException` is thrown, but doesn't distinguish between the 
lazy-wrapper path (new code) and a direct `XMLStreamException` translation 
(existing code). If a future Woodstox release changes how `WstxLazyException` 
chains its cause, the catch block becomes a no-op that re-throws the original 
`WstxLazyException` as an unchecked exception — and both `assertThrows` calls 
would fail with the wrong exception type rather than pass, which is good — but 
if the catch became incorrect in a subtler way the test would still pass.
   
   More importantly, the test doesn't verify the _message_ or _cause_ of the 
thrown exception. If the fix were accidentally removed, the unchecked 
`WstxLazyException` would propagate right through 
`assertThrows(XmlPullParserException.class, ...)` and cause a test failure — so 
the test does serve as a regression guard. However, consider strengthening it:
   
   ```suggestion
           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");
   ```



##########
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;

Review Comment:
   💡 **Sibling readers have the same gap** — `SettingsXpp3Reader`, 
`MavenToolchainsXpp3Reader`, and `MetadataXpp3Reader` all delegate to 
Woodstox-backed StAX readers using the same `catch (XMLStreamException e)` 
pattern, with no `RuntimeException` wrapper. A malformed character reference in 
`~/.m2/settings.xml`, `toolchains.xml`, or repository metadata will produce an 
escaping `WstxLazyException` from those readers too.
   
   `MavenXpp3ReaderEx` is fine — it inherits the fix through `super`.
   
   This PR should either extend the same catch block to `SettingsXpp3Reader`, 
`MavenToolchainsXpp3Reader`, and `MetadataXpp3Reader`, or file a follow-up 
issue tracking the remaining exposure (since those readers are in separate 
modules and the OSS-Fuzz target only covers `maven-model`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to