Skip to content

Issue #13672: Kill mutation for DetailAstImpl-3#13391

Merged
romani merged 1 commit intocheckstyle:masterfrom
Kevin222004:com3
Sep 7, 2023
Merged

Issue #13672: Kill mutation for DetailAstImpl-3#13391
romani merged 1 commit intocheckstyle:masterfrom
Kevin222004:com3

Conversation

@Kevin222004
Copy link
Copy Markdown
Contributor

@Kevin222004 Kevin222004 commented Jul 12, 2023

Issue #13672: Kill mutation for DetailAstImpl-3

https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/DetailAstImpl.java


Mutations

<mutation unstable="false">
<sourceFile>DetailAstImpl.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.DetailAstImpl</mutatedClass>
<mutatedMethod>addNextSibling</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.MemberVariableMutator</mutator>
<description>Removed assignment to member variable previousSibling</description>
<lineContent>astImpl.previousSibling = this;</lineContent>
</mutation>
<mutation unstable="false">
<sourceFile>DetailAstImpl.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.DetailAstImpl</mutatedClass>
<mutatedMethod>addNextSibling</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.MemberVariableMutator</mutator>
<description>Removed assignment to member variable previousSibling</description>
<lineContent>sibling.previousSibling = astImpl;</lineContent>
</mutation>


Explaination

To add Next sibiling. The code is

public void addNextSibling(DetailAST ast) {
clearBranchTokenTypes();
clearChildCountCache(parent);
if (ast != null) {
// parent is set in setNextSibling
final DetailAstImpl sibling = nextSibling;
final DetailAstImpl astImpl = (DetailAstImpl) ast;
if (sibling != null) {
astImpl.setNextSibling(sibling);
sibling.previousSibling = astImpl;
}
astImpl.previousSibling = this;
setNextSibling(astImpl);
}
}

Line 150 and 153 is mutated

This explaination is almost similar to #13390 (comment)

lets suppose if (sibling != null) { if this statment execute then
astImpl.setNextSibling(sibling); while calling setNextSibling the previous sibling will be set at

if (nextSibling != null) {
((DetailAstImpl) nextSibling).previousSibling = this;
}

For 100% surity we can remove

public void setNextSibling(DetailAST nextSibling) {
clearBranchTokenTypes();
clearChildCountCache(parent);
this.nextSibling = (DetailAstImpl) nextSibling;
if (nextSibling != null && parent != null) {
((DetailAstImpl) nextSibling).setParent(parent);
}
if (nextSibling != null) {
((DetailAstImpl) nextSibling).previousSibling = this;
}
}

if last statment from this code in which previous sibiling are set

if (nextSibling != null) {
((DetailAstImpl) nextSibling).previousSibling = this;
}

testing puropse that this happening or not we can remove
and know if you run my updated test case it will still run know run this test by removing the mutated code it will fail.


Regression

No Diff

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-25-20/part3-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-25-20/sevntu-check-regression_part_1-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-25-20/checks-nonjavadoc-error-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-25-20/sevntu-check-regression_part_2-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-25-20/test-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-25-20/checks-only-javadoc-error-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-25-20/part1-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-25-20/part5-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-25-20/part6-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-25-20/part4-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-25-20/antlr-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-25-20/part2-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-30-48/part3-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-30-48/sevntu-check-regression_part_1-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-30-48/checks-nonjavadoc-error-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-30-48/sevntu-check-regression_part_2-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-30-48/test-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-30-48/checks-only-javadoc-error-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-30-48/part1-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-30-48/part5-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-30-48/part6-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-30-48/part4-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-30-48/antlr-report/index.html

https://kevin222004.github.io/reports/com3/2023-09-06-T-16-30-48/part2-report/index.html

@Kevin222004 Kevin222004 marked this pull request as draft July 12, 2023 19:27
@Vyom-Yadav Vyom-Yadav requested review from Vyom-Yadav, rdiachenko and romani and removed request for rdiachenko and romani July 16, 2023 10:46
@Kevin222004 Kevin222004 changed the title Issue #13321: Kill mutation for DetailAstImpl-3 Issue #13501: Kill mutation for DetailAstImpl-3 Aug 23, 2023
@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

@github-actions
Copy link
Copy Markdown
Contributor

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

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

@github-actions
Copy link
Copy Markdown
Contributor

@Kevin222004 Kevin222004 force-pushed the com3 branch 4 times, most recently from 30bdcbb to 100f78f Compare August 27, 2023 09:23
@Kevin222004 Kevin222004 marked this pull request as ready for review August 27, 2023 10:03
public void addNextSibling(DetailAST ast) {
clearBranchTokenTypes();
clearChildCountCache(parent);
if (ast != null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see that both clearXXX methods are called in setNextSibling, so you remove them here as redundant. But I don't understand why you remove the null check if (ast != null), could you explain please?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok so lets suppose if ast is null. then
in current code the process stop at if (ast != null).

But if not then my updated code is

        final DetailAstImpl sibling = nextSibling;
        final DetailAstImpl astImpl = (DetailAstImpl) ast;

        if (sibling != null) {
            astImpl.setNextSibling(sibling);
        }

        setNextSibling(astImpl);

ast is assigned to astImpl and it is used at the end of method setNextSibling(astImpl); (This is the only usage of last in whole method) know in setNextSibling(astImpl); (where atImpl is null and we are passing null to setNextImpl)

     public void setNextSibling(DetailAST nextSibling) {
        clearBranchTokenTypes();
        clearChildCountCache(parent);
        this.nextSibling = (DetailAstImpl) nextSibling;
        if (nextSibling != null && parent != null) {
            ((DetailAstImpl) nextSibling).setParent(parent);
        }
        if (nextSibling != null) {
            ((DetailAstImpl) nextSibling).previousSibling = this;
        }
    }

here

will be assigned to nextSibiling (which is parameter of method).

know to set the parent of this node and the previous sibling of the node in both the if condition it is assigned that nextSibiling != null so it will never be the node of the tree (for surety I have updated the test case to check the childcount of parent you can check testAddNextSibling2)and not affect code or generate any kind of null pointer exception.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about this logic:

        if (sibling != null) {
            astImpl.setNextSibling(sibling);
        }

It is a potential NPE here when sibling is not null but astImpl is null. Is this a possible outcome?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right. I am really sorry, I don't know how I have missed this.

This may lead to major breaks in future

I will update in next push

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

if (ast != null)

logic retrieves

@rdiachenko
Copy link
Copy Markdown
Member

@Kevin222004 could you check failed pitest please?

@Kevin222004
Copy link
Copy Markdown
Contributor Author

@rdiachenko Yes I am looking on it.

@Kevin222004 Kevin222004 changed the title Issue #13501: Kill mutation for DetailAstImpl-3 Issue #13672: Kill mutation for DetailAstImpl-3 Sep 3, 2023
@romani
Copy link
Copy Markdown
Member

romani commented Sep 3, 2023

spelling failure is known issue, nothing we can do for now, waiting for Sourceforge to respond

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.

the only mixed filling I have on growing pure unit tests. But be for AST classes it is ok.

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 Sep 4, 2023
@romani romani requested a review from Vyom-Yadav September 5, 2023 00:28
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.

LGTM!

@Kevin222004 Please do regression testing with changes of both this and #13649

@romani
Copy link
Copy Markdown
Member

romani commented Sep 6, 2023

Rebased by GitHub to be ready to report generation

@Kevin222004
Copy link
Copy Markdown
Contributor Author

@romani @Vyom-Yadav I have updated the description section with newly generated report which has no diff

@romani
Copy link
Copy Markdown
Member

romani commented Sep 6, 2023

Please fix typo, see spelling failure in CI

@romani
Copy link
Copy Markdown
Member

romani commented Sep 7, 2023

All green, merging ...

@romani romani merged commit 4e8fbd0 into checkstyle:master Sep 7, 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