No coverage for some default methods

9 views
Skip to first unread message

Jens Kaiser

unread,
Jun 13, 2024, 7:40:15 AM (11 days ago) Jun 13
to JaCoCo and EclEmma Users
Hi *,

one of my projects contains an interface with some default methods. 

public interface ExpressionVisitor<IO> {
  default handleWithException(Object expression) {
    throw new UnsupportedOperationException("unsupported"
);
  }

  default visit(Node expression, input) {
    return handleWithException(expression);
  }
}

The visit method is called directly in some tests an is never overridden. But only the handleWithException coverage can be found, not the coverage of the visit method. In the Intellij coverage tool I can see the coverage for visit.

Is this a known limitation of jacoco? 

Thank you in advance.

Marc Hoffmann

unread,
Jun 14, 2024, 3:08:48 AM (10 days ago) Jun 14
to JaCoCo and EclEmma Users
Dear Jens,

this is indeed a known limitation. Not because of the default method, but because of the exception which is always thrown. See FAQ:

Source code lines with exceptions show no coverage. Why?

JaCoCo determines code execution with so called probes. Probes are inserted into the control flow at certain positions. Code is considered as executed when a subsequent probe has been executed. In case of exceptions such a sequence of instructions is aborted somewhere in the middle and the corresponding lines of source code are not marked as covered.


Regards,
-marc


--
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/2d72316c-f8f6-42f1-8281-fa22bc724b39n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages