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

Issue #12280: Resolve Pitest suppression for SingleSpaceSeparatorCheck #12283

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 0 additions & 18 deletions .ci/pitest-suppressions/pitest-whitespace-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,4 @@
<description>replaced call to com/puppycrawl/tools/checkstyle/utils/CodePointUtil::trim with argument</description>
<lineContent>final int[] substringAfterToken = CodePointUtil.trim(</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>SingleSpaceSeparatorCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.whitespace.SingleSpaceSeparatorCheck</mutatedClass>
<mutatedMethod>visitEachToken</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
<description>removed call to com/puppycrawl/tools/checkstyle/api/DetailAST::getParent</description>
<lineContent>final DetailAST parent = node.getParent();</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>SingleSpaceSeparatorCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.whitespace.SingleSpaceSeparatorCheck</mutatedClass>
<mutatedMethod>visitEachToken</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator</mutator>
<description>replaced call to com/puppycrawl/tools/checkstyle/api/DetailAST::getParent with receiver</description>
<lineContent>final DetailAST parent = node.getParent();</lineContent>
</mutation>
</suppressedMutations>
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public void beginTree(DetailAST rootAST) {
*/
private void visitEachToken(DetailAST node) {
DetailAST currentNode = node;
final DetailAST parent = node.getParent();

do {
final int columnNo = currentNode.getColumnNo() - 1;
Expand All @@ -199,7 +198,7 @@ private void visitEachToken(DetailAST node) {
currentNode = currentNode.getFirstChild();
}
else {
while (currentNode.getNextSibling() == null && currentNode.getParent() != parent) {
while (currentNode.getNextSibling() == null && currentNode.getParent() != null) {
Copy link
Member

Choose a reason for hiding this comment

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

this will go up to a ROOT ast, we should not do this, as it will walk through all nodes in tree. It is too much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, my bad, sorry this is being huge mistake of my. I have not noticed it's a loop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@romani it is possible for any situation where the parent will get null rather then Root. I am not seen any condition for this as of know

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so I think if we write it as null it will still walk till root ast because final DetailAST parent = node.getParent(); the parent here will always null BCS node here is root node bcs node is coming for private void visitEachToken(DetailAST node) { and here node is pointing to root

Copy link
Member

Choose a reason for hiding this comment

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

I recommed to apply mutation as pitest suggest and run diff report on it (do not forget to disable all CI to speedup execution)

Copy link
Member

Choose a reason for hiding this comment

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

@Kevin222004 ,
try to remove currentNode.getParent() != null completely.

Copy link
Member

Choose a reason for hiding this comment

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

Just remove it and run diff report generation on your local or by GitHub action.
It is easy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok so as a minor update if i remove this currentNode.getParent() != null completely according to #12283 (comment) so unit test cases are failing in this situation so regression would not be generated there.
please gave a look at this as well #12283 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@romani ping

Copy link
Member

Choose a reason for hiding this comment

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

this this while condition as as.
and apply mutation to final DetailAST parent = node.getParent(); to make it final DetailAST parent = node;
and see what is missed.

sounds like we can remove final DetailAST parent = node.getParent(); completely and make while condition as
currentNode.getParent() != node

currentNode = currentNode.getParent();
}
currentNode = currentNode.getNextSibling();
Expand Down