Skip to content

[java] Review reported locations of rules #3769

@adangel

Description

@adangel

While testing pmd-github-action I've seen that GitHub adds the code annotations obviously at the reported end line.

This shows has some surprising result, e.g. for AvoidCatchingThrowable:

grafik

The "Throwable" that is caught is on line 13, the catch block is lines 13-15. It seems that this rule reports begin line 13 and end line 15 and GitHub annotates line 15.

There are other rules with similar problems (list is incomplete!)

Describe the solution you'd like
The test framework currently can check the begin line (expected-linenumbers). It should be enhanced, so that end line can also be verified.
Then all rules should be reviewed, test cases should be updated and the rules should be corrected.

Describe alternatives you've considered
I thought about changing pmd-github-action to pass only begin-line or pass begin-line as end-line, so that the annotations appear on the "correct" line. However, I think, GitHub made a sensible decision to use the end-line and display the annotation at the end. This makes sense, if the violation actually applies to a whole block. So, I'd rather fix the rules than workaround how GitHub works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    an:enhancementAn improvement on existing features / rules

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions