Skip to content

Issue #13109: Kill mutation for FullIdent.java#13178

Merged
romani merged 1 commit intocheckstyle:masterfrom
Kevin222004:API4
Jun 12, 2023
Merged

Issue #13109: Kill mutation for FullIdent.java#13178
romani merged 1 commit intocheckstyle:masterfrom
Kevin222004:API4

Conversation

@Kevin222004
Copy link
Copy Markdown
Contributor

@Kevin222004 Kevin222004 commented Jun 7, 2023

Issue #13109: Kill mutation for FullIdent.java


Mutation Covered

<mutation unstable="false">
<sourceFile>FullIdent.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.api.FullIdent</mutatedClass>
<mutatedMethod>isArrayTypeDeclaration</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator</mutator>
<description>replaced call to com/puppycrawl/tools/checkstyle/api/DetailAST::getFirstChild with receiver</description>
<lineContent>DetailAST expression = arrayDeclarator.getFirstChild();</lineContent>
</mutation>
<mutation unstable="false">
<sourceFile>FullIdent.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.api.FullIdent</mutatedClass>
<mutatedMethod>isArrayTypeDeclaration</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
<description>removed call to com/puppycrawl/tools/checkstyle/api/DetailAST::getFirstChild</description>
<lineContent>expression = expression.getFirstChild();</lineContent>
</mutation>


Explaination

So we have code :-

private static boolean isArrayTypeDeclaration(DetailAST arrayDeclarator) {
DetailAST expression = arrayDeclarator.getFirstChild();
while (expression != null) {
if (expression.getType() == TokenTypes.EXPR) {
break;
}
expression = expression.getFirstChild();
}
return expression == null;
}

in which
DetailAST expression = arrayDeclarator.getFirstChild();

is mutated as
DetailAST expression = arrayDeclarator

Here expression is assigned as arrayDeclarator.getFirstChild
when the loop is going to start it will check whether the expression is null or not know if we remove .getFirstChild then expression=arrayDeclarator know arrayDeclarator is never going to be null so the loop will always execute, in the loop we have if a condition like expression.getType() == TokenTypes.EXPR which always becomes false because ast is an arrayDeclarator token.
and then at last expression = expression.getFirstChild() hence here is the case why the removal will not affect.
the expression here is again assigned as expression.getFirstChild. so it is not possible a test case in which we can create a test where .getFirstChild() will fail if we assigned it or not it will always execute.

by removal of this effect would the loop run one time more than it was running before.


Diff Regression config: https://gist.githubusercontent.com/Kevin222004/1f89420b96e95d45a945d0f8846d0d0f/raw/ed5ab114bdbdd1359c85db6edf11c4126a0e5965/fullident.xml
Diff Regression projects: https://gist.githubusercontent.com/Kevin222004/9600f179b602d4c971bdb0a050099005/raw/360a95ed7bb60d7a0956e531199d484c4d6f6617/test-projects.properties
Report label: Regression-2

@rdiachenko
Copy link
Copy Markdown
Member

@Kevin222004 please generate a report

@rdiachenko rdiachenko self-assigned this Jun 7, 2023
@Kevin222004
Copy link
Copy Markdown
Contributor Author

@rdiachenko How can i generate report for this change

@rdiachenko
Copy link
Copy Markdown
Member

@rdiachenko How can i generate report for this change

Take few checks which use that class and generate report for them.

@romani
Copy link
Copy Markdown
Member

romani commented Jun 8, 2023

Not a class, but affected method.

This class is unfortunate API, so by API rules we do not know it can be used, it just should work in all cases.

Copy link
Copy Markdown
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok to merge as some extra testing is provided

@romani romani requested review from Vyom-Yadav and rdiachenko June 8, 2023 03:41
@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 8, 2023

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 8, 2023

Copy link
Copy Markdown
Member

@rdiachenko rdiachenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rdiachenko rdiachenko assigned Vyom-Yadav and unassigned rdiachenko Jun 8, 2023
Copy link
Copy Markdown
Member

@Vyom-Yadav Vyom-Yadav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Here we want type declaration, but not initialization
final boolean isArrayTypeDeclarationStart = nextSibling != null
&& (nextSibling.getType() == TokenTypes.ARRAY_DECLARATOR
|| nextSibling.getType() == TokenTypes.ANNOTATIONS)
&& isArrayTypeDeclaration(nextSibling);

These lines cover the prior conditions of the ast passed to the method to be non null and not of type EXPR (as if ast is of type EXPR a case exists where if EXPR is passed, it will also break from the loop).


LGTM!

@Vyom-Yadav Vyom-Yadav assigned romani and unassigned Vyom-Yadav Jun 12, 2023
@romani romani merged commit f23f241 into checkstyle:master Jun 12, 2023
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

Successfully merging this pull request may close these issues.

4 participants