Skip to content

[Java] NARGS and cognitive metrics appear incorrect for simple methods #1250

Open

Description

@CaliLuke

Summary

With rust-code-analysis-cli 0.0.25, the Java NARGS and cognitive metrics appear incorrect for a minimal class with a one-parameter method and one if statement.

Reproduction

class MetricsFixture {
  int one(int x) { if (x > 0) return x; return 0; }
  int two() { return 0; }
}

Run:

rust-code-analysis-cli -p MetricsFixture.java --metrics --output-format json --output out

Expected

Based on the documented metric meanings, method one has one argument and cognitive complexity 1; method two has zero arguments and cognitive complexity 0.

Observed

In the function-space metrics, one reports NARGS functions_min/functions_max as 3 and cognitive min/max as 0. two reports NARGS functions_min/functions_max as 2 and cognitive min/max as 0.

This makes the Java NARGS and cognitive values unsuitable for simple per-function measurements. Please clarify whether these JSON fields have different semantics or whether the Java grammar/metric implementation needs correction.

Activity

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

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions