A RetroSearch Logo

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

Search Query:

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

[apex] EmptyCatchBlock false positive with formal (doc) comments · Issue #3953 · pmd/pmd · GitHub

Affects PMD Version: 6.45.0

Rule: EmptyCatchBlock

Description: The current implementation ignores formal comments when the option allowCommentedBlocks is used. Only single line comments or multi line comments, which are not doc comments, are considered. Therefore, if there is only a doc comment in the catch block, it is considered to be empty and is reported - despite the fact, that here is a comment and the block is not empty.

This might be a false positive.

However, current test cases explicitly verify this case as being reported.

Overall, this might be a contrived example...

Background: the behaviour of this rule might be changed in pmd7 with #3893

Code Sample demonstrating the issue:

@IsTest
private class FunctionalityTest {
    static testMethod void testWithModifier() {
        try {
        } catch (Exception e) { // line 5
          /** NOK: doc comment inside of empty catch block; should be reported */
        }
}

Complete test cases:

/////////////////////////////// // doc comments /////////////////////////////// try { } catch (Exception e) { /** NOK: doc comment inside of empty catch block; should be reported */ } try { } catch (Exception e) { /** NOK: doc comment inside of empty catch block; * multiple lines * should be reported */ } try { } catch (Exception e) { /** NOK: doc comment inside of empty catch block, same line as begin; should be reported */ } try { } catch (Exception e) { /** NOK: doc comment inside of empty catch block, same line as end; should be reported */ } try { } catch (Exception e) { /** NOK: doc comment inside catch block, same line as begin/end; should be reported */ }

Expected outcome:

PMD should not report a violation at line 5. This is a false-positive.


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