Skip to content

Issue #13321: Kill mutation for DescendantTokenCheck#13375

Merged
romani merged 1 commit intocheckstyle:masterfrom
Kevin222004:dtc
Aug 15, 2023
Merged

Issue #13321: Kill mutation for DescendantTokenCheck#13375
romani merged 1 commit intocheckstyle:masterfrom
Kevin222004:dtc

Conversation

@Kevin222004
Copy link
Copy Markdown
Contributor

@Kevin222004 Kevin222004 commented Jul 7, 2023

Issue #13321: Kill mutation for DescendantTokenCheck


Check

https://checkstyle.org/checks/misc/descendanttoken.html#DescendantToken


mutation

<mutation unstable="false">
<sourceFile>DescendantTokenCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck</mutatedClass>
<mutatedMethod>&lt;init&gt;</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.MemberVariableMutator</mutator>
<description>Removed assignment to member variable limitedTokens</description>
<lineContent>@XdocsPropertyType(PropertyType.TOKEN_ARRAY)</lineContent>
</mutation>
<mutation unstable="false">
<sourceFile>DescendantTokenCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck</mutatedClass>
<mutatedMethod>&lt;init&gt;</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.MemberVariableMutator</mutator>
<description>Removed assignment to member variable counts</description>
<lineContent>private int[] counts = CommonUtil.EMPTY_INT_ARRAY;</lineContent>
</mutation>


Explaination

Test added


Regression

Diff Regression config: https://gist.githubusercontent.com/Kevin222004/14aa273cb63f5e0c9b09b80021c9662d/raw/e44a7eed1601ecce19ab969e66dd27c698281ebd/desc.xml
Diff Regression projects: https://gist.githubusercontent.com/Kevin222004/21e3934e85f802e2fbd48af06d122364/raw/604256badd733d8568064f371d55657c04b00dfd/test-projects-2.properties
Report label: Regression-1

@Vyom-Yadav
Copy link
Copy Markdown
Member

@Kevin222004 please generate reports and fix CI failures

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

@github-actions
Copy link
Copy Markdown
Contributor

Report generation failed on phase "make_report",
step "Generate report".
Link: https://github.com/checkstyle/checkstyle/actions/runs/5694738448

@romani
Copy link
Copy Markdown
Member

romani commented Jul 29, 2023

@Kevin222004 , please continue.

@romani
Copy link
Copy Markdown
Member

romani commented Jul 29, 2023

conflict with spotbugs:

INFO] --- spotbugs-maven-plugin:4.7.3.0:check (default) @ checkstyle ---
[INFO] BugInstance size is 5
[INFO] Error size is 0
[INFO] Total bugs: 5
[ERROR] Low: DescendantTokenCheck.counts not initialized in constructor and dereferenced
 in com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.countTokens(DetailAST, int)
 [com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck] At DescendantTokenCheck.java:[line 787]
 UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR

[ERROR] Low: DescendantTokenCheck.counts not initialized in constructor and dereferenced in 
com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.logAsSeparated(DetailAST)
 [com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck] At DescendantTokenCheck.java:[line 713]
 UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR

[ERROR] Low: DescendantTokenCheck.counts not initialized in constructor and dereferenced in 
com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.logAsTotal(DetailAST) 
[com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck] At DescendantTokenCheck.java:[line 754]
 UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR

[ERROR] Low: DescendantTokenCheck.limitedTokens not initialized in constructor and dereferenced in com
.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.logAsSeparated(DetailAST) 
[com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck] At DescendantTokenCheck.java:[line 712]
 UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR

[ERROR] Low: DescendantTokenCheck.limitedTokens not initialized in constructor and dereferenced in
 com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.logAsTotal(DetailAST) 
[com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck] At DescendantTokenCheck.java:[line 753]
 UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR

@romani
Copy link
Copy Markdown
Member

romani commented Jul 29, 2023

we set counts at

public void setLimitedTokens(String... limitedTokensParam) {
limitedTokens = new int[limitedTokensParam.length];
int maxToken = 0;
for (int i = 0; i < limitedTokensParam.length; i++) {
limitedTokens[i] = TokenUtil.getTokenId(limitedTokensParam[i]);
if (limitedTokens[i] >= maxToken + 1) {
maxToken = limitedTokens[i];
}
}
counts = new int[maxToken];
}

we need to suppress spotbugs violations. with comment spotbugs does not know sequence of public method executions, null dereference is not possible But it is not a problem.

@romani romani self-assigned this Jul 29, 2023
@romani
Copy link
Copy Markdown
Member

romani commented Jul 30, 2023

@romani
Copy link
Copy Markdown
Member

romani commented Aug 2, 2023

@Kevin222004 , please fix Checker

@Kevin222004
Copy link
Copy Markdown
Contributor Author

@romani
Copy link
Copy Markdown
Member

romani commented Aug 3, 2023

Add to suppression it for now

@romani
Copy link
Copy Markdown
Member

romani commented Aug 7, 2023

@Kevin222004 , this looks like simple PR to update to get approval.

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:

/** Specify set of tokens with limited occurrences as descendants. */
@XdocsPropertyType(PropertyType.TOKEN_ARRAY)
private int[] limitedTokens = CommonUtil.EMPTY_INT_ARRAY;
private int[] limitedTokens;
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 Won't this throw NPE when there is no mention of this property in the config? limitedTokens is just not there in the config. In that case counts will be null and Arrays.fill(counts, 0); will throw an NPE.

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.

/*
DescendantToken
tokens = LITERAL_SWITCH
maximumDepth = 2
- limitedTokens =
minimumNumber = 1

*/

In this type of config, an NPE would be thrown. Is limitedTokens mandatory for the user to set?

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.

Yes, should be npe.
It should be reproduced by default config usage.
@Kevin222004 , please look why it is not happening, we must have default config usage in tests.
It might be due to (default) usage in property-stle config in comment of Input.

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 not sure where things have gone wrong from my side. but done

Test Added

@Kevin222004 Kevin222004 force-pushed the dtc branch 2 times, most recently from 97c05ef to 20ec60f Compare August 13, 2023 16:58
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.

minors:

Comment on lines +279 to +281
@Test
public void testProperty() throws Exception {
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
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.

testProperty is really vague, please keep a specific name.

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 , please fix method name

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.

done

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.

Input file has values that are not default,

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 have make it simple testLimitedToken

Comment on lines +11 to +18
// ok
public class InputDescendantTokenProperty {
}

class Test {
public static void main(String[] args) {
int x = 1;
switch (x) { // ok
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.

One ok on top is enough.

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.

done

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 as raised items are resolved

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!

@Vyom-Yadav Vyom-Yadav removed their assignment Aug 15, 2023
@Vyom-Yadav Vyom-Yadav removed the request for review from rdiachenko August 15, 2023 13:18
@Vyom-Yadav
Copy link
Copy Markdown
Member

@romani Assigned it to you as 2 reviews are sufficient for PRs adding a test case to kill a mutation.

@romani romani merged commit 79e7609 into checkstyle:master Aug 15, 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.

3 participants