Skip to content

Issue #13672: Kill mutation for SummaryJavaDocCheck-11#13329

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

Issue #13672: Kill mutation for SummaryJavaDocCheck-11#13329
romani merged 1 commit intocheckstyle:masterfrom
Kevin222004:s11

Conversation

@Kevin222004
Copy link
Copy Markdown
Contributor

@Kevin222004 Kevin222004 commented Jun 29, 2023

Issue #13672: Kill mutation for SummaryJavaDocCheck-11


Check :-

https://checkstyle.org/checks/javadoc/summaryjavadoc.html#SummaryJavadoc


Mutation

<mutation unstable="false">
<sourceFile>SummaryJavadocCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck</mutatedClass>
<mutatedMethod>isInlineTagPresent</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_IF</mutator>
<description>removed conditional - replaced equality check with true</description>
<lineContent>|| ast.getType() == JavadocTokenTypes.HTML_ELEMENT</lineContent>
</mutation>


Explaination

The mutation is for (int i = 0; !found; i++) { to change !found == true which has been into for each loop and after making this changes The coverage of code will be missing as #13329 (comment) looks like #13329 (comment).

basically the extra code that has been changed is for the pattern like

    /** <h1> Some header </h1> {@inheritDoc} {@code bar1} text*/
    void bar2() {}

and

         /**
          * mm{@inheritDoc}
          */
         void foo7() {}

where their is some text before {@inheritDoc} so
instead of checking every node as per old code.

else if (child.getType() != JavadocTokenTypes.LEADING_ASTERISK
                    && !CommonUtil.isBlank(child.getText())) {

we can only check for

if ((child.getType() == JavadocTokenTypes.TEXT
                    || child.getType() == JavadocTokenTypes.HTML_ELEMENT)

as per AST they are the only two possible token in which their may be a extra text before {@inheritDoc}
using this we can get the code coverage as well mutation coverage


Regression :-


Diff Regression config: https://gist.githubusercontent.com/Kevin222004/61eaa69fe98585b6ee1882ca082362bc/raw/316ca02ce9fd290119d9bfc560f2b11e84a1b685/Summary.xml
Diff Regression projects: https://gist.githubusercontent.com/Kevin222004/21e3934e85f802e2fbd48af06d122364/raw/604256badd733d8568064f371d55657c04b00dfd/test-projects-2.properties
Report label: Report-2

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

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

@github-actions
Copy link
Copy Markdown
Contributor

Report generation failed on phase "make_report",
step "Prepare environment".
Link: https://github.com/checkstyle/checkstyle/actions/runs/5414343584

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.

@Kevin222004 Please generate the reports and update the PR desc with the rationale and reports. Fix the CI failures too.

@Kevin222004
Copy link
Copy Markdown
Contributor Author

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.

I am recalling approval, something strange happening.

@romani
Copy link
Copy Markdown
Member

romani commented Jul 2, 2023

@Kevin222004 , there is conflict and CI failures.

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Yes I solve the conflict but this is strange #13329 (comment)

@romani
Copy link
Copy Markdown
Member

romani commented Jul 2, 2023

CI failure:

[INFO] Analyzed bundle 'checkstyle' with 811 classes
[WARNING] Rule violated for class 
com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck: 
branches covered ratio is 0.99, but expected minimum is 1.00

@Vyom-Yadav
Copy link
Copy Markdown
Member

@romani
Copy link
Copy Markdown
Member

romani commented Jul 9, 2023

@Kevin222004 , please finish this PR, this is AST based javadoc Check.
If you stuck, please request explicit help from mentors.

@Vyom-Yadav
Copy link
Copy Markdown
Member

@kevin The condition is redundant as:

private static boolean startsWithInheritDoc(DetailNode root) {
boolean found = false;
final DetailNode[] children = root.getChildren();
for (int i = 0; !found; i++) {
final DetailNode child = children[i];
if (child.getType() == JavadocTokenTypes.JAVADOC_INLINE_TAG
&& child.getChildren()[1].getType() == JavadocTokenTypes.INHERIT_DOC_LITERAL) {
found = true;
}
else if (child.getType() != JavadocTokenTypes.LEADING_ASTERISK
&& !CommonUtil.isBlank(child.getText())) {
break;
}
}
return found;
}

  1. The no. of children is finite, so it would, at some time, stop on its own. (unless its really large, it would then take some time)
  2. The condition child.getType() != JavadocTokenTypes.LEADING_ASTERISK && !CommonUtil.isBlank(child.getText()) will help break from the loop in most of the regular cases.

This is one of those cases where pitest prevents from saving time.

@romani
Copy link
Copy Markdown
Member

romani commented Jul 21, 2023

@Kevin222004 , CI is red

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Kevin222004 commented Jul 21, 2023

@romani I fix this soon know in this case if pitest is happy then code coverage is not and if code coverage is happy then pitest is not. I update this.

@Vyom-Yadav
Copy link
Copy Markdown
Member

@Kevin222004 Please finish this PR, please ping if some help is required.

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.

Items:

final DetailNode[] children = root.getChildren();

for (int i = 0; !found; i++) {
for (int i = 0; true; i++) {
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.

Replace this with a for-each loop.

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.

I am again facing
image
if i use for each loop

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.

@Kevin222004 Replace this with a while loop, the condition:

child.getType() != JavadocTokenTypes.LEADING_ASTERISK && !CommonUtil.isBlank(child.getText())

would always be executed as every Javadoc tree has EOF.

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.

@Kevin222004 , ping

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.

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.

#13329 (comment)
The way how the logic is set in loop we can't use it

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

1 similar comment
@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

@Kevin222004 Kevin222004 force-pushed the s11 branch 2 times, most recently from 1a13176 to 03ac7fb Compare September 3, 2023 11:33
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 3, 2023

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

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.

item:

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 3, 2023

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Kevin222004 commented Sep 3, 2023

While running this command on local groovy ./.ci/checker-framework.groovy checker-index all the suppression is getting removed instead of new or unnecessary suppression changes. Anyone knows why this is happening

@romani
Copy link
Copy Markdown
Member

romani commented Sep 3, 2023

@Kevin222004 , please try to workaround this failure in CI.
We can create separate issue to discuss this. Better to be not blocked by this unfortunate situation.

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.

Items

@Kevin222004 Kevin222004 force-pushed the s11 branch 2 times, most recently from 7222d8c to b5a670b Compare September 4, 2023 11:03
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.

items:

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.

items:

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

@romani romani assigned Vyom-Yadav and unassigned romani Sep 4, 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.

LGTM!

Agreed, only WS, TEXT, and HTML_ELEMENT can occur, out of which the latter two can only be non-empty.

@Vyom-Yadav Vyom-Yadav assigned rdiachenko and unassigned Vyom-Yadav Sep 5, 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
Copy link
Copy Markdown
Member

rebased

@rdiachenko rdiachenko assigned romani and unassigned rdiachenko Sep 6, 2023
@romani romani merged commit 3a0f40e 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.

5 participants