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

Kover CLI report generation does not reliably with --excludeAnnotation when using JAR (instead of folder) for --classfiles #709

Closed
oliviernotteghem opened this issue Nov 23, 2024 · 8 comments
Assignees
Labels
Bug Bug issue type S: in progress Status: implementing or design in process

Comments

@oliviernotteghem
Copy link

oliviernotteghem commented Nov 23, 2024

We found instances where, when using --classfiles to point to a JAR, --excludeAnnotation does not work completely and some code that should be excluded still appear to be covered.

With the same command line have --classfiles pointing to a folder, when the JAR was unpacked, the filtering works reliably.

Example of command line invocation :
java -jar /Users/oliviern/.devxp/import-cache/4b81c0960d39ddd828f97e31aee273bf0d929d87/3c34899b72c05e31efaa6ed042ad0527573034a1/kover-cli-0.8.2.jar @bazel-bin/libraries/foundation/ui/ui-compose-ambients/test_release-kover_metadata.txt --xml bazel-bin/libraries/foundation/ui/ui-compose-ambients/test_release-kover_report.xml --html /Users/oliviern/Uber/android/bazel-testlogs/libraries/foundation/ui/ui-compose-ambients/test_release/coverage_report

content of bazel-bin/libraries/foundation/ui/ui-compose-ambients/test_release-kover_metadata.txt:

report
bazel-out/xplat-fastbuild/bin/libraries/foundation/ui/ui-compose-ambients/test_release-kover_report.ic
--title
Code-Coverage Analysis: @@//libraries/foundation/ui/ui-compose-ambients:test_release
--src
libraries/foundation/ui/ui-compose-ambients/src/main/kotlin/com/uber/ui/compose/core/ambient
--classfiles
bazel-out/xplat-fastbuild/bin/libraries/foundation/ui/ui-compose-ambients/libsrc_release.jar
--exclude
*Expose

example of code failing to be filtered out:

  @Expose
  fun composeDeps(
      analyticsClient: AnalyticsClient,
  ) =
      object : composeDependencies {
        override fun analyticsClient() = analyticsClient
      }
@oliviernotteghem oliviernotteghem added Bug Bug issue type S: untriaged Status: issue reported but unprocessed labels Nov 23, 2024
@shanshin shanshin added S: in progress Status: implementing or design in process and removed S: untriaged Status: issue reported but unprocessed labels Nov 25, 2024
@zuevmaxim
Copy link

zuevmaxim commented Nov 27, 2024

@oliviernotteghem Could you please look into the bytecode of the class inside jar, and check that the annotation is present there?
Unpack the jar, and then use javap -v -l -p <path-to-class>.class to see the bytecode. The target method should have the annotation.
While testing, I found out that ProGuard removed RetentionPolicy.CLASS annotation in my case, maybe it is something similar in your case

@oliviernotteghem
Copy link
Author

@zuevmaxim : I forgot to mention that we verified this already. The annotation is not stripped and is present in bytecode.

@shanshin
Copy link
Collaborator

@oliviernotteghem, to reproduce it locally we need reproducer project or a problematic jar file

@oliviernotteghem
Copy link
Author

Sure. Here is problematic jar
src_main.jar.zip and .ic file
test_main-kover_report.ic.zip

The code corresponds to the screenshot below.
Screenshot 2024-12-02 at 2 59 18 PM

During report generation, we use --excludeAnnotation *Expose, however you can it worked on expose() method, but not for the code in composeDeps()

@shanshin
Copy link
Collaborator

shanshin commented Dec 3, 2024

Thanks for the reproducer.
This is a specific of the current implementation, anonymous objects are compiled as nested classes, and they are included in the report as a separate class, so it must be excluded separately.

Try this way

@Expose
fun composeDeps(
) =  
  @Expose object : composeDependencies {
       // ... 
    } 

*I understand that the Expose annotation is intended for another, so for such cases, you can add another one.

@oliviernotteghem
Copy link
Author

@shanshin how would you explain filtering works when --classfiles points to a folder (containing unpacked JAR) instead of the JAR itself?

shanshin added a commit that referenced this issue Dec 10, 2024
Due to the fact that the order of class-files in jar is unstable, in some cases the annotation exclusion may not work for nested lambdas.

Fixes #709
@shanshin shanshin reopened this Dec 12, 2024
@shanshin
Copy link
Collaborator

Fixed in 0.9.0

@oliviernotteghem
Copy link
Author

Thank you very much. We upgraded to 0.9.0 and can confirm the issue is gone. There seems to be other fixes as well as our code coverage for failing module is not non-null, which materializes into a nice code coverage increase for Uber android monorepo :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug issue type S: in progress Status: implementing or design in process
Projects
None yet
Development

No branches or pull requests

3 participants