Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] EmptyCatchBlock false negative when allowCommentedBlocks=true #4928

Closed
adangel opened this issue Apr 4, 2024 · 0 comments · Fixed by #4929
Closed

[java] EmptyCatchBlock false negative when allowCommentedBlocks=true #4928

adangel opened this issue Apr 4, 2024 · 0 comments · Fixed by #4929
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Milestone

Comments

@adangel
Copy link
Member

adangel commented Apr 4, 2024

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.

@adangel adangel added the a:false-negative PMD doesn't flag a problematic piece of code label Apr 4, 2024
@adangel adangel added this to the 7.1.0 milestone Apr 4, 2024
adangel added a commit to adangel/pmd that referenced this issue Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant