Affects PMD Version:
6.0.0 (and older ones I suppose)
Rule:CyclomaticComplexity
Description:
Currently, PMD treats CFG's of lambdas that are declared but not called in a method as a part of the method's CFG which falsely increases a reported cyclomatic complexity values of such methods.
Code Sample demonstrating the issue:
Here is an example of a dummy method which is considered by PMD as having cyclomatic complexity = 12 while the expected value is below 10:
public void notSoComplex(int intInput)
{
boolean binary;
switch (intInput)
{
case 0:
binary = false;
break;
case 1:
binary = true;
break;
default:
throw new RuntimeException();
}
BiConsumer<Object, Object> lambda1 = (message, nme) ->
{
if (binary)
{
System.out.println(message);
}
else
{
System.out.println(nme);
}
};
BiConsumer<Integer, Integer> lambda2 = (nme, message) ->
{
if ((nme != 0) && (message != 0))
{
try
{
System.out.println(nme);
}
catch (IllegalArgumentException illegalArgumentException)
{
throw new RuntimeException();
}
if (binary)
{
System.out.println(nme);
}
else
{
System.out.println(nme);
if (nme != 1)
{
System.out.println(nme);
}
for (int i = 0; i < message; i++)
{
System.out.println(nme);
}
}
}
};
}
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