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

Filtering: Finally block coverage #55

Closed
mchr3k opened this issue Dec 16, 2012 · 6 comments
Closed

Filtering: Finally block coverage #55

mchr3k opened this issue Dec 16, 2012 · 6 comments
Labels
declined: duplicate ❌ This issue or pull request already exists type: enhancement

Comments

@mchr3k
Copy link

mchr3k commented Dec 16, 2012

Consider the following simple block of Java code:

try
{
  System.out.println("A");
}
catch (RuntimeException ex)
{
  System.out.println("B");
}
finally
{
  if (f())
  {
    System.out.println("finally");
  }
}

In bytecode this is transformed into the following:

try
{
  System.out.println("A");
  if (f())
  {
    System.out.println("finally");
  }
}
catch (RuntimeException ex)
{
  System.out.println("B");
  if (f())
  {
    System.out.println("finally");
  }
}
catch (Throwable th)
{
  if (f())
  {
    System.out.println("finally");
  }
  throw th;
}

The duplicates of the finally block code are all tagged with the original line numbers. This means the reported coverage of the finally block is not as expected. For example consider the conditional line:

if (f())

In the original source code it looks like there are only two branches to cover. However the coverage report claims that there are six branches to cover. This is because there are three duplications of the conditional line.

I think JaCoCo should handle finally blocks specially to track coverage of these blocks in a way that is less confusing.

@marchof
Copy link
Member

marchof commented Dec 16, 2012

This is another topic for filtering, see wiki.

@mchr3k
Copy link
Author

mchr3k commented Dec 16, 2012

The current filtering wiki page doesn't actually talk about how best to handle this code duplication caused by the implementation of finally blocks.

On the one hand there really are more paths than you would expect but on the other I'm not convinced that should actually be exposed to a user of JaCoCo.

What do you think? Should JaCoCo be combining the coverage of the duplicated finally block in a different way?

@marchof
Copy link
Member

marchof commented Dec 16, 2012

Yes, in this particular case from the developers point of view the expectation would be that the execution data from the normal and the exceptional path is combined. That's in another interesting use case filtering..

@mchr3k
Copy link
Author

mchr3k commented Dec 16, 2012

I would love to get any thoughts you might have on how to implement this kind of filter. I'm not sure whether to modify the insertion of probes or to try and reconcile coverage of the existing probes at the analysis stage.

I think it will be tricky to reliably spot the blocks of duplicated byte code without having any false positives.

@marchof
Copy link
Member

marchof commented Dec 16, 2012

I know this is tricky and might result in false positives.

In any case I see this as a analysis only feature (like all filtering) and should not affect instrumentation and probe insertion.

@marchof
Copy link
Member

marchof commented Jan 8, 2013

Merge this with our filtering story #15, added this scenario to wiki page.

@marchof marchof closed this as completed Jan 8, 2013
@jacoco jacoco locked and limited conversation to collaborators Jan 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
declined: duplicate ❌ This issue or pull request already exists type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants