JaCoCo ignoring Lombok code, is this expected?

I am using Lombok 1.18.2 and JaCoCo 0.8.3, which theoretically recognize/ignore lombok annotations. I did a test, added the lombok.addLombokGeneratedAnnotation = true param in my lombok.config and then I see the generated annotation on my target classes decompiled code.

But I am surprised to open jacoco.exec file and see that things like @Getter increase the "Total Probes" values, but keep untouched the "Executed Probes" one. Is this expected?

If so, how can SonarQube make smart use of it, if by pointing it to the jacoco.exec files, there is only information on total/hit probes? How can Sonar tell one of this probes has something to do with lombok?

1 answer

  • answered 2019-03-14 11:56 Godin

    I am using Lombok 1.18.2 and JaCoCo 0.8.3, which theoretically recognize/ignore lombok annotations.

    Not theoretically, but practically.

    Not "ignore lombok annotations", but methods annotated with @lombok.Generated, or even more precise quoting entry from 0.8.3 changelog:

    Classes and methods annotated by annotation whose retention policy is runtime or class and whose simple name contains "Generated" (previously equality was required) are filtered out during generation of report


    But I am surprised to open jacoco.exec file and see that things like @Getter increase the "Total Probes" values, but keep untouched the "Executed Probes" one. Is this expected?

    Yes, this is expected. Filtering of methods doesn't happen during instrumentation of classes (insertion of probes). exec file is not final report, it contains raw information about all probes inserted in class. Filtering of methods happens during generation of report (analysis of exec and class files), i.e. during execution of report JaCoCo Ant Task for example.

    If so, how can SonarQube make smart use of it, if by pointing it to the jacoco.exec files, there is only information on total/hit probes? How can Sonar tell one of this probes has something to do with lombok?

    SonarQube embeds JaCoCo as a library and use it to analyze exec and class files for generation of their report.

    And that's why JaCoCo release announcements usually contain following statement, e.g. for 0.8.2:

    As before - please note

    0.8.2 version of integrations developed as part of JaCoCo project by us (Ant Tasks, Maven Plugin and Command Line Interface) provide Java 11 support and new filters,

    tools that directly read exec files (which is not a final report) and embed JaCoCo as a library for generation of report will provide ability to analyze Java 11 class files and to use new filters only after they updated to this version of JaCoCo. So please follow/wait/etc respective vendors such as

    SonarQube - https://jira.sonarsource.com/browse/SONARJAVA-2876 , or try to use new plugin that reads XML report - https://github.com/SonarSource/sonar-jacoco