Skip to content

[java] Cognitive Complexity threshold cannot be set to 0 #5917

Open

Description

@edoardosarri24

Affects PMD Version: 7.15.0

Rule: CognitiveComplexity

Running PMD through: CLI

Description: The threshold value must be $s>0$. If $s=0$, the analysis does not return any files. For this reason, very simple Java files cannot be introduced into the final report.

Code Sample: The class below isn't include in the final PMD report.

public class SampleDuration {
    public static Duration sample(Sampler sampler) {
        BigDecimal sample = sampler.getSample();
        sample = sample.multiply(BigDecimal.TEN.pow(6));
        return Duration.ofNanos(sample.longValue());
    }
}

Activity

  1. added
    a:bug
    on Jul 18, 2025
  2. adangel commented on Jul 18, 2025

    @adangel
    Member

    Do I understand this correctly? Your use case is not finding complex classes, instead it is getting the metric for each class?

    This reminds me of #5166 ...

  3. edoardosarri24 commented on Jul 18, 2025

    @edoardosarri24
    Author

    Yes, exactly. This can be useful when you need to correlate metrics like CC with other information to obtain a complex report. In my case study, for example, I correlate each file with the contribution percentage of each developer that worked on that file and the CC of the file (e.g., like this csv).

    My idea is that if 1 is allowed as a threshold value, why not also allow 0? In situations where you only want to find complex classes, 1 is probably too low a threshold value and not very interesting. Introducing 0 as a threshold value makes it easier to merge multiple analyses (as in my case study).

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

    a:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions