-
Notifications
You must be signed in to change notification settings - Fork 354
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
Missing coverage in try-with-resources finally block #1375
Comments
Thanks for the report. The underlying cause of this is the way that javac implements try blocks, creating duplicate inlined copies of the code. Pitest does contain some handling for this, but it hasn't been updated for many years and was always imperfect. I'll take another look and see if it can be improved and if there have been any changes to the pattern of bytecode that recent versions of javac emit. |
@Wouter684 There seems to be an issue with the linked repo pitest-try-with-resources-bug/src/test/java/org/example/MyClassTest.java:[47,85] cannot find symbol
[ERROR] symbol: method getFirst() |
That is strange, for me the test worked. Perhaps you are not yet using java 21 on your machine? I updated the repo to replace |
@Wouter684 ah, you're correct, it was picking up java 11. All fine with 21. |
Describe the bug
When running a pitest on a class with a try-with-resources and a finally block, the logic in the finally block is not covered by the VoidMethodCallMutator. There is a test case which fails when the method call is removed, but when pitest removes that method call the mutation survives according to pitest.
Expected behavior
The mutation should be killed when the method call is removed and the pitest should have full coverage on that line, because the method call is covered in a test case.
Actual behavior
The mutation survives even though there is coverage to ensure that the removed line is executed.
How to Reproduce?
https://github.com/Wouter684/pitest-try-with-resources-bug
Run the pitest in the project. (mvn clean test org.pitest:pitest-maven:mutationCoverage)
Output of
java -version
Quarkus version or git rev
3.17.5
Build tool (ie. output of
mvnw --version
orgradlew --version
)Additional information
When running pitest with verbose logging, the result shows that for VoidMethodCallMutator, 3 mutations are generated but only 2 are killed. However, when looking through the verbose logs, only 2 of these mutations are actually executed and logged, the third never even occurs in the logging.
The entire mutation case that is not killed never shows up in the logging, as if the mutation has not been executed at all. Even though it shows up in the results as "No coverage" and the pitest fails over the missing coverage
The text was updated successfully, but these errors were encountered: