Skip to content

[java] Inconsistent line range in RuleViolation for CognitiveComplexity rule between PMD 6.54.0 and 7.0.0-rc1 #4439

@chenlingmin

Description

@chenlingmin

Affects PMD Version: 6.54.0 and 7.0.0-rc1

Description:

When using the CognitiveComplexity rule for Java in PMD 6.54.0, the RuleViolation returns the line range covering the entire method, from the start to the end (e.g., 3-7 in the provided example). However, when using PMD 7.0.0-rc1, it only returns the line number of the method signature (e.g., 3-3 in the provided example).

Code Sample demonstrating the issue:

public class Example {

    public void sampleMethod() { // Line 3
        if (true) {
            System.out.println("Hello, world!");
        }
    } // Line 7
}

Steps to reproduce:

Please provide detailed steps for how we can reproduce the bug.

  1. Run PMD 6.54.0 with the CognitiveComplexity rule on the provided code sample.
  2. Observe the RuleViolation line range covering the entire method (3-7).
  3. Run PMD 7.0.0-rc1 with the CognitiveComplexity rule on the same code sample.
  4. Observe the RuleViolation line range only covering the method signature (3-3).

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bugPMD crashes or fails to analyse a file.

    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