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

Conversation

Kevin222004
Copy link
Collaborator

@Kevin222004 Kevin222004 commented Oct 9, 2022

@Kevin222004
Copy link
Collaborator Author

Kevin222004 commented Oct 9, 2022

  1. pitest report

    https://kevin222004.github.io/general/com.puppycrawl.tools.checkstyle.checks.whitespace/SingleSpaceSeparatorCheck.java.html
    removed call to com/puppycrawl/tools/checkstyle/api/DetailAST::getParent
    replaced call to com/puppycrawl/tools/checkstyle/api/DetailAST::getParent with receiver

  2. Mutated code

    current code
    final DetailAST parent = node.getParent();
    is Mutated to
    final DetailAST parent = node;

  3. Analysis

    The current situation of code final DetailAST parent = node.getParent();
    in this if we see closely to the method from which this line of code belong

        private void visitEachToken(DetailAST node) {
        DetailAST currentNode = node;
        final DetailAST parent = node.getParent();
    
    

    Now here In private void visitEachToken(DetailAST node) { node is always be our compilation unit
    ex( the AST I have provided of one test file).

    Now the final DetailAST parent = node.getParent(); here parent is calling getParent() to get
    the parent node of node which is compilation unit now obvivously compilation is going to the root of tree
    so it become always null

    now final DetailAST parent = node.getParent(); the parent is using by method at one place only
    at while (currentNode.getNextSibling() == null && currentNode.getParent() != parent) {
    now the parent is always being null so we change it as null

    AST for test file https://github.com/checkstyle/checkstyle/blob/master/src/test/resources/com/puppycrawl/tools/checkstyle/checks/whitespace/singlespaceseparator/InputSingleSpaceSeparatorMinColumnNo.java

COMPILATION_UNIT -> COMPILATION_UNIT [8:0]
|--PACKAGE_DEF -> package [8:0]
|   |--ANNOTATIONS -> ANNOTATIONS [8:57]
|   |--DOT -> . [8:57]
|   |   |--DOT -> . [8:46]
|   |   |   |--DOT -> . [8:39]
|   |   |   |   |--DOT -> . [8:28]
|   |   |   |   |   |--DOT -> . [8:22]
|   |   |   |   |   |   |--DOT -> . [8:11]
|   |   |   |   |   |   |   |--IDENT -> com [8:8]
|   |   |   |   |   |   |   `--IDENT -> puppycrawl [8:12]
|   |   |   |   |   |   `--IDENT -> tools [8:23]
|   |   |   |   |   `--IDENT -> checkstyle [8:29]
|   |   |   |   `--IDENT -> checks [8:40]
|   |   |   `--IDENT -> whitespace [8:47]
|   |   `--IDENT -> singlespaceseparator [8:58]
|   `--SEMI -> ; [8:78]
`--CLASS_DEF -> CLASS_DEF [10:0]
    |--MODIFIERS -> MODIFIERS [10:0]
    |   `--LITERAL_PUBLIC -> public [10:0]
    |--LITERAL_CLASS -> class [10:7]
    |--IDENT -> InputSingleSpaceSeparatorMinColumnNo [10:13]
    `--OBJBLOCK -> OBJBLOCK [10:50]
        |--LCURLY -> { [10:50]
        |--VARIABLE_DEF -> VARIABLE_DEF [11:4]
        |   |--MODIFIERS -> MODIFIERS [11:4]
        |   |--TYPE -> TYPE [11:4]
        |   |   `--LITERAL_INT -> int [11:4]
        |   |--IDENT -> j [12:0]
        |   |--ASSIGN -> = [12:3]
        |   |   `--EXPR -> EXPR [12:5]
        |   |       `--NUM_INT -> 0 [12:5]
        |   `--SEMI -> ; [12:6]
        `--RCURLY -> } [13:0]

   `````


4. How to kill this

    removed the `final DetailAST parent = node.getParent();` and change the parent as null in method 

Copy link
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.

item:

@@ -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
Collaborator 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
Collaborator 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
Collaborator 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
Collaborator 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
Collaborator 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

@Kevin222004
Copy link
Collaborator Author

Kevin222004 commented Oct 9, 2022

as of know the whole approach is may wrong

@Kevin222004
Copy link
Collaborator Author

I am generating a diff report to just analyize

@Kevin222004
Copy link
Collaborator Author

Github, generate report

1 similar comment
@Kevin222004
Copy link
Collaborator Author

Github, generate report

@github-actions
Copy link
Contributor

Report generation job failed on phase "make_report", step "Generate report".
Link: https://github.com/checkstyle/checkstyle/actions/runs/3218449711

@Kevin222004
Copy link
Collaborator Author

Github, generate report

@rnveach rnveach self-requested a review October 10, 2022 12:43
@rnveach
Copy link
Member

rnveach commented Nov 12, 2022

@Kevin222004 ping

@Kevin222004
Copy link
Collaborator Author

@Kevin222004 ping

sorry for no activity on this pr from, long after #12283 (comment)
I have tried to remove it, the tree is traversing perfectly as expectation but wherever violation is expected it is giving
some error so unit test are failing . I am not able to work on it as it take time. because of examination, but i am trying to figure it out. and complete the pr

@rnveach
Copy link
Member

rnveach commented Nov 12, 2022

Let us know when you think you may return.
I would recommend to provide the difference reports that were requested, and post that URL in #12283 (comment) with a brief summary (differences or no differences) and we will continue from there.

@Kevin222004
Copy link
Collaborator Author

Let us know when you think you may return.

for this pr and all the issue related to Pitest I will comeback around December starting

@rnveach
Copy link
Member

rnveach commented Jan 7, 2023

I am taking over resolving this mutation, so I am closing this PR for my own.

@rnveach rnveach closed this Jan 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants