hcoles / pitest

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

Pitest creates equivalent mutations #1230

Open Vyom-Yadav opened 1 year ago

Vyom-Yadav commented 1 year ago

Mutator: https://pitest.org/quickstart/mutators/#EXPERIMENTAL_MEMBER_VARIABLE

It is also documented that:

Please Note: This mutator is likely to create equivalent mutations if a member variable is explicitly initialized with the Java default value for the specific type of the member variable as in

public class EquivalentMutant {
private int x = 0;
}

It was recently faced when a final field was initialized to null in a constructor. Removing the initialization is not possible as it will give a compile-time error.

Screenshot from 2023-06-12 15-03-23

/**                                                                   
 * The charset used to read the file.                                 
 * {@code null} if the file was reconstructed from a list of lines.   
 */                                                                   
private final Charset charset;                                        

Though this is already documented, would it be possible to fix this? I.e. to mutate the member variable with the default value only when it has a non-default value?

Vyom-Yadav commented 1 year ago

@hcoles ping

hcoles commented 1 year ago

Yes, it should now be possible to fix this. A static analysis filtering system was introduced long after this mutator was created that ought to be able to handle this. Similar filters have been created for the default operators, but the non defaults have been overlooked. Thanks for the suggestion.

romani commented 1 year ago

@hcoles , is there any plan to fix this issue ?

or may be you just share a bit more links to code on how to do this (based on your comment similar problem was fixed in some other part) and somebody from web can send a fix.