Skip to content

[java] Review reported locations of rules #3769

Open

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.

Activity

  1. added
    an:enhancement
    on Feb 10, 2022
  2. adangel commented on Feb 22, 2022

    @adangel
    MemberAuthor

    See also #730

  3. UncleOwen commented on Sep 6, 2025

    @UncleOwen
    Member

    See also #5906 #5905 #5904 #5669 #5668 #5614 #5613 for [apex]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    an:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions