A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/3569 below:

[apex] EmptyCatchBlock rule should provide an option to ignore empty catch blocks in test methods · Issue #3569 · pmd/pmd · GitHub

Affects PMD Version: 6.39.0

Rule: EmptyCatchBlock

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/pmd-6.39.0/pmd_rules_apex_errorprone.html#emptycatchblock

Description:

There's at least one situation where empty catch blocks are actually expected and even support a best practices approach to the problem being solved, specifically in Apex unit tests when verifying that an expected exception has been thrown.

An options should be added to the EmptyCatchBlock rule to allow instance of this pattern to be ignored.

Code Sample demonstrating the issue:

    @IsTest
    static void testAddAllNotNull() {
        try {
            // This should throw an IllegalStateException if provided a null list
            CollectionUtil.addAllNotNull((List<Object>) null, null);
            System.assert(false, 'Expected an IllegalArgumentException for a null list.');
        } catch (IllegalArgumentException e) {
            // Expected, but this gets flagged by the PMD Apex EmptyCatchBlock rule
        }
    }

Expected outcome:

I imagine for backward-compatibility, a new option would be added that defaults to the current behavior if unspecified, e.g.:

   <rule ref="category/apex/documentation.xml/EmptyCatchBlock" message="...">
      <priority>3</priority>
      <properties>
         <property name="reportInTestMethods" value="false" />
      </properties>
   </rule>

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
CLI and direct API-based integration


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4