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


##########
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:
   Fixed in fb33f54055 — test now captures the thrown exception and asserts 
`assertInstanceOf(XMLStreamException.class, ex.getCause())` for both the Reader 
and InputStream paths.



##########
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:
   Fixed in fb33f54055 — extended the same `catch (RuntimeException e)` guard 
to `SettingsXpp3Reader` (4 Reader/InputStream methods, XMLStreamReader overload 
left as-is), `MavenToolchainsXpp3Reader` (the single Reader method; InputStream 
overloads delegate to it), and `MetadataXpp3Reader` (4 Reader/InputStream 
methods, XMLStreamReader overload left as-is).



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