Skip to content

Issue #13999: Resolve Pitest suppression for ancestor.getType() == TokenTypes.LITERAL_TRY of JavadocMethod#14410

Merged
nrmancuso merged 1 commit into
checkstyle:masterfrom
sktpy:issue-13999-literal-try-jadadoc
Feb 12, 2024
Merged

Issue #13999: Resolve Pitest suppression for ancestor.getType() == TokenTypes.LITERAL_TRY of JavadocMethod#14410
nrmancuso merged 1 commit into
checkstyle:masterfrom
sktpy:issue-13999-literal-try-jadadoc

Conversation

@sktpy

@sktpy sktpy commented Feb 2, 2024

Copy link
Copy Markdown
Contributor

Part of #13999

(Check Documentation)

Mutation:

<mutation unstable="false">
<sourceFile>JavadocMethodCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheck</mutatedClass>
<mutatedMethod>isInIgnoreBlock</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.RemoveConditionalMutator_EQUAL_IF</mutator>
<description>removed conditional - replaced equality check with true</description>
<lineContent>if (ancestor.getType() == TokenTypes.LITERAL_TRY</lineContent>
</mutation>


Definitions:

  1. and-expression:-
ancestor.getType() == TokenTypes.LITERAL_TRY
&& ancestor.findFirstToken(TokenTypes.LITERAL_CATCH) != null	
  1. first-operand: ancestor.getType() == TokenTypes.LITERAL_TRY
  2. second-operand: ancestor.findFirstToken(TokenTypes.LITERAL_CATCH) != null
  3. mutant: replacing first-operand with true.

Why mutant survives:

  • mutant does not alters the result of and-expression because LITERAL_CATCH cannot exist without being the child of LITERAL_TRY.
  • This makes evaluating first-operand not a necessity because second-operand being evaluated as true implicitly means that the type of ancestor is LITERAL_TRY.

Why mutant cannot be killed:

  • For this, there needs to be an input where LITERAL_CATCH exist without a preceding LITERAL_TRY block
  • This results in compilation error and hence is not possible.

Why not remove second-operand:

  • The and-expression is meant to evaluate if the throw is inside a try block which has a corresponding catch block.
  • Unlike catch block, which cannot exist without a try block, try block can exist without a catch block.

⚠️ Performance Impact:

  • Benefit due to short circuiting in and-expression should be weighed in before merging this PR.
  • If ancestor is not LITERAL_TRY, findFirstToken() is not only useless for the reason that it won't find a LITERAL_CATCH ;
  • But along with that, it may impact performance if ancestor has a significant number of children.
  • This is avoided by short circuiting in and-expression but results in the surviving mutant.

Change:

Updated the code as Pitest mutated, except it is now the last operand of the or-statement to help mitigate the performance impact by a bit.
(Although this shifting of operands may produce negligible performance gains, still better than none)


Usage:

Definition and the only usage for the method with mutant is in JavadocMethodCheck. (1 usage)
JavadocMethodCheck does not affect any other class.
Call Stack:

isInIgnoreBlock:691, JavadocMethodCheck (com.puppycrawl.tools.checkstyle.checks.javadoc)
  getThrowed:640, JavadocMethodCheck (com.puppycrawl.tools.checkstyle.checks.javadoc)
    checkComment:442, JavadocMethodCheck (com.puppycrawl.tools.checkstyle.checks.javadoc)
      processAST:392, JavadocMethodCheck (com.puppycrawl.tools.checkstyle.checks.javadoc)
        visitToken:374, JavadocMethodCheck (com.puppycrawl.tools.checkstyle.checks.javadoc)
          notifyVisit:335, TreeWalker (com.puppycrawl.tools.checkstyle)
            processIter:408, TreeWalker (com.puppycrawl.tools.checkstyle)
              ...

Regression:

Result: No differences found. (Report)

Diff Regression config: https://gist.githubusercontent.com/sktpy/44a31ea4e946a0755fa3e331fd65de98/raw/233b4d68f7cd46f957ee37e94813922d5fd1733c/check.xml

Diff Regression projects: https://gist.githubusercontent.com/sktpy/49239940660ceaef88d224d6abc8878e/raw/058cbb1b662c9276e934fdffbb99cec760332398/projects-to-test-on.properties

@sktpy sktpy marked this pull request as draft February 2, 2024 18:48
@sktpy

sktpy commented Feb 2, 2024

Copy link
Copy Markdown
Contributor Author

GitHub, generate report

@rnveach

rnveach commented Feb 2, 2024

Copy link
Copy Markdown
Contributor

@sktpy How did you get that exclamation icon in your post?

@github-actions

github-actions Bot commented Feb 2, 2024

Copy link
Copy Markdown
Contributor

@sktpy sktpy force-pushed the issue-13999-literal-try-jadadoc branch from d114536 to 4e720b7 Compare February 2, 2024 22:54
@sktpy sktpy changed the title Issue #13999: Resolve Pitest suppression for 'ancestor.getType() == T… Issue #13999: Resolve Pitest suppression for ancestor.getType() == TokenTypes.LITERAL_TRY of JavadocMethod Feb 2, 2024
@sktpy

sktpy commented Feb 2, 2024

Copy link
Copy Markdown
Contributor Author

@rnveach GitHub supports rendering of emojis in Markdown, which extends to the comments as well.
I have Characters app (link), it can fetch results for emojis directly in the system search.
You can also use unicodes for the corresponding emojis.

Another way is github's emoji markup, which would be :warning: for that emoji. (Full list)
You can type :(colon) followed by the text, and matching emojis will popup.

@sktpy sktpy marked this pull request as ready for review February 2, 2024 23:55
@sktpy sktpy force-pushed the issue-13999-literal-try-jadadoc branch 2 times, most recently from 360059d to d5c7146 Compare February 4, 2024 10:02
…ype() == TokenTypes.LITERAL_TRY` of JavadocMethod
@sktpy sktpy force-pushed the issue-13999-literal-try-jadadoc branch from d5c7146 to 2c6df13 Compare February 4, 2024 11:18
@sktpy

sktpy commented Feb 4, 2024

Copy link
Copy Markdown
Contributor Author

GitHub, generate report

@github-actions

github-actions Bot commented Feb 4, 2024

Copy link
Copy Markdown
Contributor

@romani romani requested a review from rnveach February 5, 2024 16:31
@sktpy sktpy requested a review from rnveach February 7, 2024 04:44

@romani romani left a comment

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.

thanks a lot for wide explanation.
I placed your PR as example to issue description to let others do similar.

@sktpy

sktpy commented Feb 9, 2024

Copy link
Copy Markdown
Contributor Author

The pleasure was all mine, mutant hunting is a lot of fun 👾 👾 👾

@nrmancuso nrmancuso merged commit 1b1d376 into checkstyle:master Feb 12, 2024
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