Jacoco showing filtered code in coverage report

205 views
Skip to first unread message

tuk

unread,
Jun 24, 2022, 8:01:37 AM6/24/22
to JaCoCo and EclEmma Users
I have added a filter via annotation to exclude a method from jacoco coverage as mentioned here.

But when I see the jacoco html report for coverage I see the filtered method being shown in red as not covered. Please check the attached screenshot. Is this expected?

Jacoco Version - 0.8.8

Screenshot 2022-06-24 at 5.30.07 PM.png
Screenshot 2022-06-24 at 5.30.07 PM.png

Marc Hoffmann

unread,
Jun 24, 2022, 8:50:12 AM6/24/22
to JaCoCo and EclEmma Users
Hi,

can you please double check that your annotation has the retention policy CLASS or RUNTIME?

regards,
-marc


On 24. Jun 2022, at 14:01, tuk <subhara...@gmail.com> wrote:

I have added a filter via annotation to exclude a method from jacoco coverage as mentioned here.

But when I see the jacoco html report for coverage I see the filtered method being shown in red as not covered. Please check the attached screenshot. Is this expected?

Jacoco Version - 0.8.8

<Screenshot 2022-06-24 at 5.30.07 PM.png>

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/05fca62e-c828-4bea-97ab-0f6b4c30560fn%40googlegroups.com.
<Screenshot 2022-06-24 at 5.30.07 PM.png><Screenshot 2022-06-24 at 5.30.07 PM.png>

tuk

unread,
Jun 24, 2022, 11:09:56 AM6/24/22
to JaCoCo and EclEmma Users
Yes, it has. 

package com.spotnana.common;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ExcludeFromJacocoGeneratedReport {}


tuk

unread,
Jun 24, 2022, 1:33:26 PM6/24/22
to JaCoCo and EclEmma Users
Just to add in the method level summary the excluded method is not showing up (get() method is missing). But when I go inside the class then the uncovered code is shown in red. 


excluded.png

Marc Hoffmann

unread,
Jun 24, 2022, 1:37:42 PM6/24/22
to JaCoCo and EclEmma Users
Ok. In this case what you see is the code of the lambda body. Technically the compiler creates a method for it which is not excluded. I’m afraid this is a limitation of the @Generated annotation.


On 24. Jun 2022, at 19:33, tuk <subhara...@gmail.com> wrote:

Just to add in the method level summary the excluded method is not showing up (get() method is missing). But when I go inside the class then the uncovered code is shown in red. 


tuk

unread,
Jun 24, 2022, 1:47:39 PM6/24/22
to JaCoCo and EclEmma Users
Can you please explain what exactly is the limitation? If I don't use the @Generated annotation then get() method shows up in the method level summary.

notExcluded.png

tuk

unread,
Jun 24, 2022, 1:52:54 PM6/24/22
to JaCoCo and EclEmma Users
get() method is excluded. But compiler internally created a method for lambda which is shown in red in the class level report?

Marc Hoffmann

unread,
Jun 24, 2022, 3:05:00 PM6/24/22
to jac...@googlegroups.com
Exactly!

Currently JaCoCo filtering is implemented method by method in one pass. So we cannot corelate merthods (i.e. which lambda body method was call from which annotated method) 

On 24. Jun 2022, at 19:53, tuk <subhara...@gmail.com> wrote:

get() method is excluded. But compiler internally created a method for lambda which is shown in red in the class level report?

tuk

unread,
Jun 25, 2022, 9:22:58 AM6/25/22
to JaCoCo and EclEmma Users
Thanks, Marc for replying.

Is there any open enhancement request for this feature or it is not possible to implement?

Marc Hoffmann

unread,
Jun 26, 2022, 7:13:08 AM6/26/22
to jac...@googlegroups.com
Hi, there are currently no plans for this as it would probably require a major rework of analyser.

Reply all
Reply to author
Forward
0 new messages