I have a piece of code that basically looks like this:
public MyObject getData(boolean someFlag) { String select1 = "SELECT * FROM myTable WHERE someInteger = ?"; SqlHostvariablen hostvars = new SqlHostvara(); hostvars.addInteger(myField.getSomeInteger); String[][] selarray = SqlHelper.doSelectAsMatrix(select1, hostvars); if (selarray.length == 0) { throw new IllegalArgumentException("Nothing found"); } MyObject foo = new MyObject(); int i = 0; foo.setSomething1(selarray[0][i++]); foo.setSomething2(selarray[0][i++]); foo.setSomething3(selarray[0][i++]); foo.setSomething4(selarray[0][i++]); foo.setSomething5(selarray[0][i++]); foo.setSomething6(selarray[0][i++]); foo.setSomething7(selarray[0][i++]); foo.setSomething8(transformSomething8(selarray[0][i++])); foo.setSomething9(selarray[0][i++]); foo.setSomething10(selarray[0][i++]); String someValue1 = selarray[0][i++]; String someValue2 = selarray[0][i++]; foo.setSomething11(selarray[0][i++]); doSomethingWithFoo(foo, someFlag, someValue1, someValue2); doSomethingElseWithFoo(foo); return foo; }
Identifiers and the SQL statement are anonymized, but otherwise my method looks the same.
Now Checkstyle claims that cyclic complexity if this method is 12. I always thought I know what CC is, and from my knowledge I would say that these CC methods are 2. There is one if that creates a new path through therefore The control flow code and graph have 2 paths / exit points. I do not see where else there should be a path through the code.
Am I missing something completely or is Checkstyle just wrong?
source share