Skip to content
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

code might be less elegant if chained call of cast to type is present #1304

Open
Kevin222004 opened this issue Jan 31, 2024 · 0 comments
Open

Comments

@Kevin222004
Copy link

whenever some type casting has been done using .map

    private Set<String> getExternalResourceLocations() {
        return Stream.concat(fileSetChecks.stream(), filters.getFilters().stream())
            .filter(ExternalResourceHolder.class::isInstance)
            .map(ExternalResourceHolder.class::cast)
            .flatMap(resource -> resource.getExternalResourceLocations().stream())
            .collect(Collectors.toSet());
    }
 <mutation unstable="false"> 
   <sourceFile>Checker.java</sourceFile> 
   <mutatedClass>com.puppycrawl.tools.checkstyle.Checker</mutatedClass> 
   <mutatedMethod>getExternalResourceLocations</mutatedMethod> 
   <mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator</mutator> 
   <description>replaced call to java/util/stream/Stream::map with receiver</description> 
   <lineContent>.map(ExternalResourceHolder.class::cast)</lineContent> 
 </mutation> 

pitest will suggest the NakedReceiverMutator if we follow pitest in this case then .map() needs to be removed and if we do that then the code cannot be compilable.

we have faced this issue at checkstyle/checkstyle#13913 and checkstyle/checkstyle#13913.
as the solution we have done changes like

    private Set<String> getExternalResourceLocations() {
        return Stream.concat(fileSetChecks.stream(), filters.getFilters().stream())
            .filter(ExternalResourceHolder.class::isInstance)
            .flatMap(resource -> {
                return ((ExternalResourceHolder) resource)
                        .getExternalResourceLocations().stream();
            })
            .collect(Collectors.toSet());
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant