-
Notifications
You must be signed in to change notification settings - Fork 365
NakedReceiverMutator demands removal of map(MyClass.class::cast) but java compiler requires it #1270
Copy link
Copy link
Open
Description
Detected at checkstyle/checkstyle#13928
code:
public Set<String> getExternalResourceLocations() {
return Stream.concat(filters.stream(),
Stream.concat(ordinaryChecks.stream(), commentChecks.stream()))
.filter(ExternalResourceHolder.class::isInstance)
.map(ExternalResourceHolder.class::cast)
.flatMap(resource -> resource.getExternalResourceLocations().stream())
.collect(Collectors.toSet());
}
mutation is:
org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator
replaced call to java/util/stream/Stream::map with receiver
on line .map(ExternalResourceHolder.class::cast)
Workaround to avoid mutation is usage of old style cast in lambda:
public Set<String> getExternalResourceLocations() {
return Stream.concat(filters.stream(),
Stream.concat(ordinaryChecks.stream(), commentChecks.stream()))
.filter(ExternalResourceHolder.class::isInstance)
.flatMap(resource -> {
return ((ExternalResourceHolder) resource)
.getExternalResourceLocations().stream();
})
.collect(Collectors.toSet());
}
but code does not looks good in this case.
We do know that pitest operates on bytecode so cast chain method is actually not required especially in code where it is close to impossible to put wrong type in collection.
Is it possible to improve pitest to skip such mutations ?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels