hcoles / pitest

State of the art mutation testing system for the JVM
Apache License 2.0
1.71k stars 357 forks source link

Unreachable Mutant, ENUM::lambda$static$0 #1273

Open Shawn-Armstrong opened 1 year ago

Shawn-Armstrong commented 1 year ago

I've encountered a mutant that I wasn't able to remove in a Java 17 code base using PITest (1.15.0) in conjunction with JUnit5 (5.9.3) test cases. The code is a bit niche and poorly written but I managed to recreate it in this repository.

Details

hcoles commented 1 year ago

Thanks for the report and the reproducable sample.

The problem is that this is a mutation called only from static initialization code. This means the code is exectued only once per jvm and causes multiple problems for mutation testing (theres an entry on this in the FAQ which I can't link to as I seem to have cunningly include no anchors in the page).

Pitest avoids mutating code in static initializers and tries to avoid mutating code called only from static initializers. The filtering doesn't seem to be working in this case, probably because the code predates lambdas and hasn't been updated.

hcoles commented 1 year ago

The analysis was indeed failing to consider invokeDynamic calls. A fix has been merged and will be in the next release.

Thanks again for the high quality bug report.

hcoles commented 3 months ago

@Shawn-Armstrong

This took a bit more work than expected as the initial fix resulted in the suppression of valid mutants when code execution was delayed and had to be reverted.

1.16.3 is now released which should solve these issues.