Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CC_CYCLOMATIC_COMPLEXITY calculation is wrong #407

Open
riverwinddk opened this issue Aug 31, 2020 · 0 comments
Open

CC_CYCLOMATIC_COMPLEXITY calculation is wrong #407

riverwinddk opened this issue Aug 31, 2020 · 0 comments

Comments

@riverwinddk
Copy link

riverwinddk commented Aug 31, 2020

The result from the Cyclomatic Complexity (CC_CYCLOMATIC_COMPLEXITY) detector (CyclomaticComplexity.java) reports 6 for the following method:

int f(int i, int j) {
    int result;
    if(i % 2 == 0) {
        result = i + j;
    }
    else {
        if(j % 2 == 0) {
            result = i * j;
        }
        else {
            result = i - j;
        }
    }
    return result;
}

The result should be 3, as documented here.

It seems to be quite consistent, that the reported CC is higher than the real CC, Unfortunately my understanding of the control flow graph in Spotbugs is insufficient to suggest how to fix this.

@riverwinddk riverwinddk changed the title Cyclomatic complexity calculation is wrong CC_CYCLOMATIC_COMPLEXITY calculation is wrong Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants