-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mutate delayed execution code stored in statics
We don't want to mutate code executed only during static initialization. Unfortunately the current filtering also picks up code that is executed after static initialization as lambdas. This change implelements an imperfect comprimise where code stored as Suppliers, Functions etc will be considered for mutation. This will fail to mutate delayed execution code stored in other types, and will incorrectly mutate code that is executed only during initialization if it is within a method that returns a Supplier etc. Although imperfect, it is an improvement.
- Loading branch information
Showing
5 changed files
with
191 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
pitest-entry/src/test/java/com/example/staticinitializers/EnumFieldSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.staticinitializers; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public enum EnumFieldSupplier { | ||
A(canMutate()); | ||
|
||
private final Supplier<String> supplier; | ||
|
||
EnumFieldSupplier(Supplier<String> supplier) { | ||
this.supplier = supplier; | ||
} | ||
|
||
private static Supplier<String> canMutate() { | ||
// don't mutate | ||
System.out.println("ideally would mutate me"); | ||
|
||
return () -> "Do not mutate"; // mutate | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
pitest-entry/src/test/java/com/example/staticinitializers/StaticFunctionField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example.staticinitializers; | ||
|
||
import java.util.function.Function; | ||
|
||
public class StaticFunctionField { | ||
private static final Function<String,String> FOO = canMutate(); | ||
|
||
private static Function<String, String> canMutate() { | ||
// don't mutate | ||
System.out.println("ideally would mutate me"); | ||
|
||
return s -> s + "foo"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
pitest-entry/src/test/java/com/example/staticinitializers/StaticSupplierField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example.staticinitializers; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class StaticSupplierField { | ||
final static Supplier<String> SUPPLER = canMutate(); | ||
|
||
private static Supplier<String> canMutate() { | ||
// don't mutate | ||
System.out.println("ideally would mutate me"); | ||
|
||
return () -> "Do not mutate"; // mutate | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters