-
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
try with resources block generates unkillable mutants #255
Comments
Could you provide a more detailed example and a full report for that class? I'm not sure whether those mutations are really "unkillable": You might have to simulate throwing an exception from the close() method directly and after an exception has already been thrown in the try-block and examine the suppressed exception(s) available via The try-with-resources block is just a handy shortcut the compiler provides. Taken from http://www.oracle.com/technetwork/articles/java/trywithresources-401775.html the code
is just a shortcut for
The survived mutations are just the calls removed from the finally block I guess. You've to check that logic as well to kill those mutants. |
Ok, but there is no reason for me to test auto-generated code, this stuff On Tue, Apr 19, 2016 at 1:26 PM, Stefan Penndorf notifications@github.com
|
PITEST works on the bytecode level. |
Nevertheless this "auto-generated" code ships with some semantics and changes the behaviour of your method. I don't agree that this is auto-generated code which shouldn't be tested. If you don't need the behaviour or if you don't rely on that behaviour just don't use try-with-resources. If you use try-with-ressources you SHOULD check at least:
The last thing is the only "feature" that feels like an optional behaviour because it does not change the behaviour of your code if you don't query for suppressed exceptions. As @tobijdc correctly mentioned those instructions might be really hard to detect because they will be introduced by the compiler and I'm not sure whether we can distinguish between manual implementation and compiler "expansion" |
I have the same problem. Using try-with-resources creates unkillable mutants. It is pointless to test whether try-with-resources works. The whole point of try-with-resources is to prevent mistakes. Testing whether try-with-resources works makes test code unnecessarily complicated. How would you test something like this:
In particular, the |
As far as I understand, this should be discovered by the
I'll share more details once I've created an isolated test case. |
@pbludov possibly. The bytecode that is generated for try with resources varies by compiler (java, eclipse, others) and by java version. The change in #860 is confirmed to work with java eclipse, javac8 and javac11. There may be issues with other compilers or java versions not tested for, and it might be possible to trip it up with more complex code than has been tested for. Guess it's a question for @zygoth about whether they still see this problem. |
Is there some way to ignore these try-with-resource branches? |
@Manfred73 What version of pitest are you using? Using temurin-17.0.5 (17.0.4 doesn't look to be available via sdkman) I do not see these mutants for roughly equivalent code for pitest 1.11.0. The only way to ignore them is to improve pitest's filtering, or use the exclusions functionality from arcmutate. https://docs.arcmutate.com/docs/exclusions.html If you can create a minimal project that reproduces this issue, I can look at improving the filtering. |
If you use a try-with-resources block in your Java code and run PITest on it, you get about 8 MUTANT SURVIVED messages on the closing brace of your try block. This is quite frustrating as it can drive down the overall mutant coverage percentage by a lot. This seems like an obvious bug. The messages all look like one or the other of these:
removed call to com/blah/MyClassExtendsCloseable::close \u2192 SURVIVED
removed call to java/lang/Throwable::addSuppressed \u2192 SURVIVED
The text was updated successfully, but these errors were encountered: