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 #11720: Kill surviving mutation in RequireThisCheck related to static blocks #11792

Conversation

Vyom-Yadav
Copy link
Member

@Vyom-Yadav Vyom-Yadav commented Jun 29, 2022

#11720
Hardcoded mutation tested at #11776

Reports with hardcoded mutation (clean):

validateOnlyOverlapping = false report was not generated with OpenJDK (Out of memory in GitHub actions), though it is very unlikely that it will show any difference, still, if it is required, ping me, and I will generate it locally.

This mutation falls in the category:

  • Safely (no regressions) remove code to be covered

Rationale:

The condition definitionToken.getType() == TokenTypes.STATIC_INIT is same as the condition
codeBlockDefinition.getType() == TokenTypes.STATIC_INIT. A variable declared in static block scope, will always have an enclosing CLASS_FRAME.

In the current logic, we skip all frames of type BLOCK_FRAME, and FOR_FRAME to reach the CLASS_FRAME, if we can't reach CLASS_FRAME (maybe METHOD_FRAME is in between), then we can be assured that there is no static block present.

So if there is a static block, we will surely go into the branch
if (variableDeclarationFrame.getType() == FrameType.CLASS_FRAME) in which we check for the condition-

staticContext = codeBlockDefinition.getType() == TokenTypes.STATIC_INIT
    || modifiers.findFirstToken(TokenTypes.LITERAL_STATIC) != null;

Hence the line can be safely removed, in theory, we would take a hit in TC, as we would make another traversal in getCodeBlockDefinitionToken(..) but in reality, there will be no difference, in real case use scenario, 2-3 more iterations.


Generating reports again:

Diff Regression config: https://gist.githubusercontent.com/Vyom-Yadav/98dceb63a79f4833e85fff9b2e1464a6/raw/5dc88b466a50335d5759f60c1d041a239f11a5a1/my_checks.xml
Diff Regression projects: https://gist.githubusercontent.com/Vyom-Yadav/91807e6244cff60698d9e33e32ba2d51/raw/ccf3b6b9e053f27b371eb6d1e848d7199dd1f567/projects-to-test-on.properties
Report label: validateOnlyOverlappingFalseWithoutOpenJDK

@Vyom-Yadav Vyom-Yadav force-pushed the killSurvivingMutationInRequireThisCheck-3 branch 2 times, most recently from becba42 to dc3d699 Compare June 29, 2022 08:45
Copy link
Member

@nrmancuso nrmancuso left a comment

Choose a reason for hiding this comment

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

Please generate check regression reports for this PR.

@Vyom-Yadav
Copy link
Member Author

Github, generate report

@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2022

@Vyom-Yadav
Copy link
Member Author

Github, generate report

@Vyom-Yadav Vyom-Yadav force-pushed the killSurvivingMutationInRequireThisCheck-3 branch from dc3d699 to fb921c5 Compare July 1, 2022 07:12
@github-actions
Copy link
Contributor

github-actions bot commented Jul 1, 2022

@nrmancuso nrmancuso merged commit b87a6c0 into checkstyle:master Jul 1, 2022
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.

None yet

3 participants