Issue #13109: Kill mutation for UnusedLocalVariableCheck 2#13145
Issue #13109: Kill mutation for UnusedLocalVariableCheck 2#13145romani merged 1 commit intocheckstyle:masterfrom
Conversation
|
Github, generate report |
|
Github, generate report |
|
Github, generate report |
|
please correct me if I missed anything |
|
Github, generate report |
|
@romani This is ready fir review |
|
@Kevin222004 , Checker is not happy. |
|
Can u please re run circle ci they are not related to changes I guess |
|
@Kevin222004 reran CircleCI, all workflows there are green. Failure in semaphore is known and not related to your changes. |
| final DetailAST ident = varDefAst.findFirstToken(TokenTypes.IDENT); | ||
| final VariableDesc desc = new VariableDesc(ident.getText(), | ||
| varDefAst.findFirstToken(TokenTypes.TYPE), findScopeOfVariable(varDefAst)); | ||
| null, null); |
There was a problem hiding this comment.
I too analyzed the code and yes, changing it to null won't have any effect because:
DetailAST typeAstis only used while logging violations, and we only log violations for local variables, and thisVariableDescis for an instance or class variable.DetailAST scope. We never use the initially set scope. When we usescope, we update it to our value before using it. Seewe useupdatedScopeinstead.
So all in all, we can safely do these changes BUT this is not a good design. The design of the check should be altered to not have situations like these. This is out of the scope of this summer's project, a separate issue to enhance the design of the check should be created.
LGTM!
There was a problem hiding this comment.
Ok, I don't have time now to investigate in detail.
We will deal with this in separate project
|
@Kevin222004 please resolve conflicts |
|
Conflict resolved |
| final DetailAST ident = varDefAst.findFirstToken(TokenTypes.IDENT); | ||
| final VariableDesc desc = new VariableDesc(ident.getText(), | ||
| varDefAst.findFirstToken(TokenTypes.TYPE), findScopeOfVariable(varDefAst)); | ||
| null, null); |
There was a problem hiding this comment.
Considering VariableDesc is a nested private class, can we introduce another constructor VariableDesc(String name) and remove those null arguments?
There was a problem hiding this comment.
@rdiachenko done
There is no such solution for new surviving mutation.
hcoles/pitest#1230
There was a problem hiding this comment.
@Kevin222004 you can reuse another constructor to set values, please update it to the following:
private VariableDesc(String name) {
this(name, null, null);
}
There was a problem hiding this comment.
Why not ?
private VariableDesc(String name) {
this.name = name;
}
And it will avoid Checker problems mostlikely
There was a problem hiding this comment.
I don't see reply to #13145 (comment)
If code is by design, we should just explain Checker that fields are nullable.
There was a problem hiding this comment.
@romani I have tried what you say it leads to other new suppression and after solving it it leads to some other suppression I request you to not cover this here please if you want to check I can update the pr.
If you want to complete it allow me to create a new pr and complete it please do not cover this pr.
|
@Kevin222004 Please fix CI failures. |
Issue #13109: Kill mutation for UnusedLocalVariableCheck 2
check:-
https://checkstyle.org/config_coding.html#UnusedLocalVariable
Mutation Covered :-
checkstyle/config/pitest-suppressions/pitest-coding-2-suppressions.xml
Lines 273 to 308 in 9580515
Explaination :-
This might not be a good changes but still,
Here in the method
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnusedLocalVariableCheck.java
Lines 509 to 518 in 9580515
the code
is mutated as
Know if we look at class VariableDec constructor
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnusedLocalVariableCheck.java
Lines 864 to 867 in 9580515
2nd and 3rd parameter is being registered as typeAst and scope.
know if we see in the whole check the usage of typeAst and scope of variableDesc class is only to log the violation at
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnusedLocalVariableCheck.java
Lines 423 to 432 in 9580515
hence their is no other usage of this.
know the method will only register instance variables and class variables on which we are throwing violation
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnusedLocalVariableCheck.java
Lines 503 to 509 in 9580515
As per my analysis using input it is not possible to cover this.
Diff Regression config: https://gist.githubusercontent.com/Kevin222004/0dbdfb487f8e9a050ed0e6356f1a35b4/raw/31f7927f400e11e4285e86fd086b373095227848/unusedLocal.xml
Diff Regression projects: https://gist.githubusercontent.com/Kevin222004/21e3934e85f802e2fbd48af06d122364/raw/604256badd733d8568064f371d55657c04b00dfd/test-projects-2.properties
Report label: Latest-Report-2