Affects PMD Version: 7.12.0
Rule:
NPathComplexity
Description:
The rule NPathComplexity
does not discriminate between if
statements and if
statements which just contain a return
instruction.
Code Sample demonstrating the issue:
int foo(int x) { if(x==0) return 0; if(x==1) return 1; if(x==2) return 2; if(x==3) return 3; if(x==4) return 4; if(x==5) return 5; if(x==6) return 6; if(x==7) return 7; if(x==8) return 8; if(x==9) return 9; return x; }
This code triggers NPathComplexity
with a value of 1024, when the correct number should be 11.
Adding brackets for each if
or replacing the return
with a throw
does not change the reported number.
Expected outcome:
I am asking to extend the rule NPathComplexity
in order to account for trivial cases in which there is only one obvious path inside the if
body, or at least add a new property to enable this kind of distinction. With this definition I mean any block of code, ending in either a throw
or a return
, without if
s or loops.
What are your thoughts on this?
Running PMD through: Gradle
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4