You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
I have a method in a class:
public boolean tryFile() throws IOException {
File file = File.createTempFile("test", "dat");
file.deleteOnExit();
try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(20);
}
return file.exists();
}
According OpenClover documentation:
Method Complexity
Cyclomatic complexity of a single method. It's calculated as follows:
empty method complexity == 1
simple statement complexity == 0
switch block complexity == number of case statements
try catch block complexity == number of catch statements
ternary expression complexity == 1
boolean expression complexity == number of && or || in expression
In report generated by OpenClover (version 4.4.1) the complexity for this method equals 3. Why? How it was counted?
PS. For example in JaCoCo report I see Ctx=1 for this method.
tryCatchBlock [boolean labelled] returns [CloverToken last]
{
last = null;
int complexity = 0;
ContextSet saveContext = getCurrentContext();
}
: tr:"try" (lp:LPAREN {insertAutoCloseableClassDecl((CloverToken)tr);} declaration {complexity++; instrArmDecl(((CloverToken)lp).getNext(), (CloverToken)LT(0), saveContext);} (semi:SEMI declaration {complexity++; instrArmDecl(((CloverToken)semi).getNext(), (CloverToken)LT(0), saveContext);})* (SEMI)? rp:RPAREN )?
{enterContext(ContextStore.CONTEXT_TRY); saveContext = getCurrentContext();}
last=compoundStatement
{exitContext();}
(last=handler {complexity++;})*
( "finally"
{enterContext(ContextStore.CONTEXT_FINALLY); saveContext = getCurrentContext();}
last=compoundStatement
{exitContext();}
)?
{ if (!labelled) {
instrInlineBefore((CloverToken)tr, last, saveContext, complexity);
}
}
;
* 1st comes from the try-with-resources block:
try (FileOutputStream fos = new FileOutputStream(file))
* 2nd comes from the method entry as per docs
I'm not sure about the 3rd one...
Happy New Year! We hope you all had a safe and restful holiday season. 2020 was a unique year full of unforeseen events; however, as we enter the new year of 2021, we’re optimistic for the light at t...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.