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

Pitest not filtering try-with-resources correctly in Java 11 #766

Closed
johnsterken opened this issue May 14, 2020 · 5 comments
Closed

Pitest not filtering try-with-resources correctly in Java 11 #766

johnsterken opened this issue May 14, 2020 · 5 comments

Comments

@johnsterken
Copy link

johnsterken commented May 14, 2020

Summary

Pitest is trying to mutate bytecode used for closing resources when using the try-with-resources in Java 11

Expected: No mutations on the generated parts of the bytecode, this behaviour works correctly in Java 8
Actual: Mutations happening on the generated parts in the bytecode used for closing the resources that are used in the try block

Steps to reproduce

Other info

Probably this is related to #689

Tested with OpenJDK

Java 11

openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu218.04)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu218.04, mixed mode, sharing)

Java 8

openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~18.04-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

I also checked out the pitest repository locally. When I create a test in TryWithResourcesFilterTest with the Java 11 bytecode from my local JDK I don't see any mutation being filtered. When I run the same test on a Java 8 class file it does filter out mutations

java8_pit_report.zip
java11_pit_report.zip

@ketan2505
Copy link

I am using pitest results for quality checks. The same problem occured with me. I had to disable pitest from my project. I would like to see this working with Java 11 as well.

@TomerFi
Copy link

TomerFi commented Feb 6, 2021

Same here.
Working with Java11, using try-with-resources, I always end up with a bunch of surviving mutants.
e.g. a mutant removing the close() statement inside the auto-generated finally block.

@hcoles
Copy link
Owner

hcoles commented Feb 16, 2021

Sorry for the delay fixing this folks, it is very annoying. Should have something out early next week.

hcoles pushed a commit that referenced this issue Feb 16, 2021
Javac emits fewer null checks for try with resources in 11 than in 8.
This trips up the junk mutation filtering.

This change broadens the filtering to catch java 11 generated code and
changes the implementation to use the bytecode matching system.
hcoles pushed a commit that referenced this issue Feb 16, 2021
Javac emits fewer null checks for try with resources in 11 than in 8.
This trips up the junk mutation filtering.

This change broadens the filtering to catch java 11 generated code and
changes the implementation to use the bytecode matching system.
@hcoles
Copy link
Owner

hcoles commented Feb 16, 2021

This has gone a little easier than I'd exepected, so I'll push a release out later today.

New filtering catches the issues in @johnsterken 's example, plus some sample real world projects. I expect there will be further issues with more complex examples, but current code seems to give 90% of the benefit.

@johnsterken
Copy link
Author

Looking good! I just tried your 1.6.3 version in the project that triggered this issue. It's working like a charm. Thanks @hcoles!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants