question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
hcolescommented, 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.

2reactions
hcolescommented, Feb 16, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

try with resources block generates unkillable mutants #255
If you use a try-with-resources block in your Java code and run PITest on it, ... Somehow it seems that it is currently...
Read more >
FAQ - PIT Mutation Testing
Make sure that your code and tests are properly referenced on the classpath, and check that the filters are not excluding your code....
Read more >
JaCoCo and PITest - No mutations found. This probably ...
JaCoCo and PITest - No mutations found. This probably means there is an issue with either the supplied classpath or filters. 2283 views....
Read more >
Pit Mutation Test: tests found, no minions possible
I use the PIT Mutation Test for a huge java programm (over 450.000 LOC). ... [INFO] Found plugin : Try with resources filter...
Read more >
The try-with-resources Statement - Exceptions
This Java tutorial describes exceptions, basic input/output, concurrency, regular expressions, and the platform environment.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found