You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2020/08/13 12:33:01 UTC

[maven-shared-utils] branch ex created (now 7e02766)

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

elharo pushed a change to branch ex
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git.


      at 7e02766  fix exception handling

This branch includes the following new commits:

     new 7e02766  fix exception handling

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-shared-utils] 01/01: fix exception handling

Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch ex
in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git

commit 7e027660a2ce91555d5f667d8a6adf11a78bec66
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Thu Aug 13 08:32:41 2020 -0400

    fix exception handling
---
 .../maven/shared/utils/xml/Xpp3DomBuilder.java     | 22 ++++++++++-----------
 .../maven/shared/utils/xml/Xpp3DomBuilderTest.java | 23 +++++++++++++++++++++-
 2 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java
index 00f6f0b..f5ed1aa 100644
--- a/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java
+++ b/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java
@@ -46,8 +46,8 @@ public class Xpp3DomBuilder
 
     /**
      * @param reader {@link Reader}
-     * @return the built dom.
-     * @throws XmlPullParserException in case of an error.
+     * @return the built DOM
+     * @throws XmlPullParserException in case of an error
      */
     public static Xpp3Dom build( @WillClose @Nonnull Reader reader )
         throws XmlPullParserException
@@ -57,9 +57,9 @@ public class Xpp3DomBuilder
 
     /**
      * @param is {@link InputStream}
-     * @param encoding The encoding.
-     * @return the built dom.
-     * @throws XmlPullParserException in case of an error.
+     * @param encoding the encoding
+     * @return the built DOM
+     * @throws XmlPullParserException in case of an error
      */
     public static Xpp3Dom build( @WillClose InputStream is, @Nonnull String encoding )
         throws XmlPullParserException
@@ -69,10 +69,10 @@ public class Xpp3DomBuilder
 
     /**
      * @param is {@link InputStream}
-     * @param encoding The encoding.
-     * @param trim true/false.
-     * @return the built dom.
-     * @throws XmlPullParserException in case of an error.
+     * @param encoding the encoding
+     * @param trim true/false
+     * @return the built DOM
+     * @throws XmlPullParserException in case of an error
      */
     public static Xpp3Dom build( @WillClose InputStream is, @Nonnull String encoding, boolean trim )
         throws XmlPullParserException
@@ -84,14 +84,14 @@ public class Xpp3DomBuilder
         }
         catch ( UnsupportedEncodingException e )
         {
-            throw new RuntimeException( e );
+            throw new XmlPullParserException( e );
         }
     }
 
     /**
      * @param reader {@link Reader}
      * @param trim true/false
-     * @return the built dom
+     * @return the built DOM
      * @throws XmlPullParserException in case of an error
      */
     public static Xpp3Dom build( @WillClose Reader in, boolean trim )
diff --git a/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java b/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
index 9aaca9f..a236ede 100644
--- a/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
+++ b/src/test/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilderTest.java
@@ -24,11 +24,16 @@ import org.apache.maven.shared.utils.xml.pull.XmlPullParserException;
 
 import org.junit.Test;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.StringReader;
 import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 
@@ -42,7 +47,7 @@ public class Xpp3DomBuilderTest
 
     private static final String xmlDeclaration = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
 
-        @Test
+    @Test
     public void selfClosingTag()
         throws Exception
     {
@@ -58,6 +63,22 @@ public class Xpp3DomBuilderTest
     }
 
     @Test
+    public void testUnrecognizedEncoding()
+    {
+
+        byte[] data = "<foo/>".getBytes(StandardCharsets.UTF_8);
+        InputStream in = new ByteArrayInputStream( data );
+        try {
+            Xpp3DomBuilder.build( in , "nosuch encoding" );
+            fail();
+        } catch ( XmlPullParserException expected ) {
+            assertTrue( expected.getCause() instanceof UnsupportedEncodingException );
+        }
+
+    }
+
+    
+    @Test
     public void trimming()
         throws Exception
     {