pmd / pmd

An extensible multilanguage static code analyzer.

Home Page:https://pmd.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[java] EmptyCatchBlock false negative when allowCommentedBlocks=true

adangel opened this issue · comments

Affects PMD Version: 7.0.0

Rule: EmptyCatchBlock

Description:

As commented on #4871 (review) - for Apex, formal (doc) comments are dealt the same way like other comments now. No special treatment.

I thought, EmptyCatchBlock does the same, since there was a test case explicitly for javadoc comments saying "Javadoc comment is not OK"... but a test case with allowCommentedBlock was missing for javadoc comments.

So it turns out, that for Java, javadoc comments are not treated specially as well. So the Apex and Java rule are similar now.

But testing further showed, it's a bit worse: When the rule is configured with allowCommentedBlocks=true, then empty catch blocks are not found anymore...

Code Sample demonstrating the issue:

public class Foo {
    void bar() {
        try {} catch (Exception e) {}
    }
}

Expected outcome:

PMD should report a violation at line 3, but doesn't. This is a false-negative.