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

elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-pmd-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 2bc5682  [MPMD-412] More specific catch blocks (#642)
2bc5682 is described below

commit 2bc568204d3e01162dc38e35976c029e85a9785c
Author: Elliotte Rusty Harold <elh...@users.noreply.github.com>
AuthorDate: Sat Jul 5 08:36:49 2025 -0400

    [MPMD-412] More specific catch blocks (#642)
    
    * [MPMD-412] More specific catch blocks
    * remove debugging stacktrace
    * better TODO
---
 .../maven/plugins/pmd/exec/CpdReportConsumer.java  |  3 +++
 .../apache/maven/plugins/pmd/CpdReportTest.java    | 23 +++++++---------------
 2 files changed, 10 insertions(+), 16 deletions(-)

diff --git 
a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdReportConsumer.java 
b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdReportConsumer.java
index 4e6a04b..df7f5f2 100644
--- a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdReportConsumer.java
+++ b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdReportConsumer.java
@@ -64,6 +64,9 @@ class CpdReportConsumer implements Consumer<CPDReport> {
                 writeFormattedReport(report);
             }
         } catch (IOException | MavenReportException e) {
+            // TODO this should be a more specific subclass; or just have the 
accept method
+            // build the objects in memory and write them to a stream later 
after the
+            // accept method returns
             throw new RuntimeException(e);
         }
     }
diff --git a/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java 
b/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java
index fb5e836..bfd5fd2 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java
@@ -50,8 +50,6 @@ public class CpdReportTest extends AbstractPmdReportTestCase {
 
     /**
      * Test CPDReport given the default configuration
-     *
-     * @throws Exception
      */
     public void testDefaultConfiguration() throws Exception {
         File generatedReport =
@@ -72,8 +70,6 @@ public class CpdReportTest extends AbstractPmdReportTestCase {
 
     /**
      * Test CPDReport with the text renderer given as "format=txt"
-     *
-     * @throws Exception
      */
     public void testTxtFormat() throws Exception {
         generateReport(getGoal(), 
"custom-configuration/cpd-txt-format-configuration-plugin-config.xml");
@@ -94,8 +90,6 @@ public class CpdReportTest extends AbstractPmdReportTestCase {
 
     /**
      * Test CpdReport using custom configuration
-     *
-     * @throws Exception
      */
     public void testCustomConfiguration() throws Exception {
         File generatedReport =
@@ -118,8 +112,6 @@ public class CpdReportTest extends 
AbstractPmdReportTestCase {
 
     /**
      * Test CPDReport with invalid format
-     *
-     * @throws Exception
      */
     public void testInvalidFormat() throws Exception {
         try {
@@ -130,8 +122,9 @@ public class CpdReportTest extends 
AbstractPmdReportTestCase {
                     mojo, "compileSourceRoots", 
mojo.getProject().getCompileSourceRoots());
             generateReport(mojo, testPom);
 
-            fail("MavenReportException must be thrown");
-        } catch (Exception e) {
+            // TODO this should be a more specific subclass
+            fail("RuntimeException must be thrown");
+        } catch (RuntimeException e) {
             assertMavenReportException("Can't find CPD custom format xhtml", 
e);
         }
     }
@@ -259,13 +252,11 @@ public class CpdReportTest extends 
AbstractPmdReportTestCase {
     }
 
     private static void assertMavenReportException(String expectedMessage, 
Exception exception) {
+        MavenReportException cause = (MavenReportException) 
exception.getCause();
+        String message = cause.getMessage();
         assertTrue(
-                "Expected MavenReportException, but was: " + exception,
-                exception.getCause() instanceof MavenReportException);
-        exception = (Exception) exception.getCause();
-        assertTrue(
-                "Wrong message: expected: " + expectedMessage + ", but was: " 
+ exception.toString(),
-                exception.toString().contains(expectedMessage));
+                "Wrong message: expected: " + expectedMessage + ", but was: " 
+ message,
+                message.contains(expectedMessage));
     }
 
     private static void assertReportContains(String expectedMessage) throws 
IOException {

Reply via email to