Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kapishyadav
Copy link
Contributor

Issue #14894

  • Removed suppressions pitest-coding-2-suppressions.xml for UnusedLocalVariableCheck
  • Removed excluding SLS_SUSPICIOUS_LOOP_SEARCH bug for UnusedLocalVariableCheck
  • Removed Lambda optimization for getBlockContainingLocalAnonInnerClass in UnusedLocalVariableCheck .java following Commit becac62
  • Added 2 unit tests (testUnusedLocalVarInDeepAnonInnerClasses and testGetBlockContainingLocalAnonInnerClassTraversal) to kill surviving PIT mutations related to traversal logic in this method by testing its behavior on deeply nested anonymous inner classes.

@kapishyadav
Copy link
Contributor Author

kapishyadav commented Oct 25, 2025

Looks like the build is failing but interestingly when I run "mvn clean verify", the build succeeds locally including checkstyle checks. Not sure if I am missing something here. Unfortunately I am unable to reproduce the checkstyle errors for the test code locally where the build fails. Error on Github CI at ci/semaphoreci/pr: Checkstyle CI pipeline on Semaphore

[ERROR] [checkstyle] [ERROR] /home/semaphore/checkstyle/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/UnusedLocalVariableCheckTest.java:228:9: Loops should not contain more than a single "break" or "continue" statement [SingleBreakOrContinue]02:32
[INFO]      [echo] Checkstyle finished (/home/semaphore/checkstyle/config/checkstyle-sevntu-checks.xml): 25/10/2025 03:02:58 PM02:32
[INFO] ------------------------------------------------------------------------02:32
[INFO] BUILD FAILURE

These are the commands I used for checking build and pitest suppressions-

  1. mvn clean verify

  2. groovy .ci/pitest-survival-check-xml.groovy --list

  3. export PITEST_PROFILE=pitest-coding-2

  4. mvn -e --no-transfer-progress -P"$PITEST_PROFILE" clean test-compile org.pitest:pitest-maven:mutationCoverage

  5. groovy .ci/pitest-survival-check-xml.groovy "$PITEST_PROFILE"

Output:

kapishyadavbanda@Kapishs-MBP checkstyle % groovy .ci/pitest-survival-check-xml.groovy "$PITEST_PROFILE"
No new surviving mutation(s) found.

Killed Mutations (locally):
For line 447 :
while (currentAst != null && !TokenUtil.isOfType(currentAst, ANONYMOUS_CLASS_PARENT_TOKENS))

1. negated conditional → KILLED
2. removed call to com/puppycrawl/tools/checkstyle/utils/TokenUtil::isOfType → KILLED
3. negated conditional → KILLED
4. removed conditional - replaced equality check with false → KILLED
5. removed conditional - replaced equality check with false → KILLED
6. removed conditional - replaced equality check with true → KILLED
7. removed conditional - replaced equality check with true → KILLED

Environments:

Apache Maven 3.9.11 (3e54c93a704957b63ee3494413a2b544fd3d825b)
Maven home: /Users/kapishyadavbanda/.sdkman/candidates/maven/current
Java version: 21.0.8, vendor: Amazon.com Inc., runtime: /Users/kapishyadavbanda/.sdkman/candidates/java/21.0.8-amzn
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "26.1", arch: "aarch64", family: "mac"

Please do let me know if I am missing something trivial.

@romani
Copy link
Member

romani commented Oct 25, 2025

[INFO] [checkstyle] Running Checkstyle 10.4 on 2243 files
[ERROR] [checkstyle] [ERROR] C:\projects\checkstyle\src\test\java\com\puppycrawl\tools\checkstyle\checks\coding\UnusedLocalVariableCheckTest.java:228:9: Loops should not contain more than a single "break" or "continue" statement [SingleBreakOrContinue]
[INFO]

@romani
Copy link
Member

romani commented Oct 25, 2025

Github, generate report for UnusedLocalVariable/all-examples-in-one

@github-actions
Copy link
Contributor

@romani
Copy link
Member

romani commented Oct 25, 2025

Ok, just one violation to resolve

@romani
Copy link
Member

romani commented Oct 26, 2025

Github, generate report for UnusedLocalVariable/all-examples-in-one

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.

items:

Comment on lines +211 to +217
public void testGetBlockContainingLocalAnonInnerClassTraversal() throws Exception {
final UnusedLocalVariableCheck check = new UnusedLocalVariableCheck();

final DetailAST root = JavaParser.parseFile(
new File(getPath("InputUnusedLocalVariableAnonInnerClassesDeepNesting.java")),
JavaParser.Options.WITHOUT_COMMENTS
);
Copy link
Member

Choose a reason for hiding this comment

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

all tests should be only by verifyWithInlineConfigParser.

Copy link
Contributor Author

@kapishyadav kapishyadav Oct 26, 2025

Choose a reason for hiding this comment

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

I found similar tests from line 511 onwards -

public void testClearStateAnonInnerClass() throws Exception {

So I tried using similar ways to test the traversal to kill mutations. I used verifyWithInlineConfigParser to parse the resource test file InputUnusedLocalVariableAnonInnerClassesDeepNesting.java violations.

Would you like me to move this test to the end of the file?

Copy link
Member

Choose a reason for hiding this comment

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

testClearStateAnonInnerClass()

Is very special to confirm that all fields are cleared between executions on different files.

Better to add comment over it that this method very special allowance to not use general verifyWithInlineConfigParser

@github-actions
Copy link
Contributor

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.

2 participants