Skip to content

creation of mutable collection consider as can be avoided #1300

@Kevin222004

Description

@Kevin222004
        public Set<DetailAST> getMethodCalls() {
            return Collections.unmodifiableSet(methodCalls);
        }

this code has been mutated as

        public Set<DetailAST> getMethodCalls() {
            return methodCalls;
        }

for

 <mutation unstable="false"> 
   <sourceFile>EqualsAvoidNullCheck.java</sourceFile> 
   <mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck$FieldFrame</mutatedClass> 
   <mutatedMethod>getMethodCalls</mutatedMethod> 
   <mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.ArgumentPropagationMutator</mutator> 
   <description>replaced call to java/util/Collections::unmodifiableSet with argument</description> 
   <lineContent>return Collections.unmodifiableSet(methodCalls);</lineContent> 
 </mutation> 

Modifying the code with Pitest from return Collections.unmodifiableSet(methodCalls) to return new HashSet<>(methodCalls) eliminates the guarantee of returning an unmodifiable set, potentially leading to unintended modifications and inconsistent behavior.

we have faced this issue at checkstyle/checkstyle#13127
and checkstyle/checkstyle#13126

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions