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 #13038: handled inner class method definition in VariableDeclarationUsageDistanceCheck #14635

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

@jxr98
Copy link
Contributor Author

jxr98 commented Mar 10, 2024

GitHub, generate report

@jxr98
Copy link
Contributor Author

jxr98 commented Mar 10, 2024

I've read the pitest wiki and the pitest mutation overview. I understand removed conditional - replaced equality check with true mutation, but don't see how it applies to the code. I have tried to replace the first == with equal and remove it. It doesn't seem right. Can anyone help me? Thanks.

image

@nrmancuso
Copy link
Member

I've read the pitest wiki and the pitest mutation overview. I understand removed conditional - replaced equality check with true mutation, but don't see how it applies to the code. I have tried to replace the first == with equal and remove it. It doesn't seem right. Can anyone help me? Thanks.

image

I am fairly certain this means that now the ONLY tokens that are passed to this method are in these conditions, so we might as well return true from the isZeroDistanceToken method, which means that where ever this method is used could probably be mutated to just true as well. Try to remove this method completely and see what happens.

@jxr98 jxr98 force-pushed the ff branch 2 times, most recently from 0425b43 to d762894 Compare April 1, 2024 02:07
@jxr98
Copy link
Contributor Author

jxr98 commented Apr 1, 2024

I've read the pitest wiki and the pitest mutation overview. I understand removed conditional - replaced equality check with true mutation, but don't see how it applies to the code. I have tried to replace the first == with equal and remove it. It doesn't seem right. Can anyone help me? Thanks.
image

I am fairly certain this means that now the ONLY tokens that are passed to this method are in these conditions, so we might as well return true from the isZeroDistanceToken method, which means that where ever this method is used could probably be mutated to just true as well. Try to remove this method completely and see what happens.

Thanks. I've tried to return true or false in the isZeroDistanceToken method and remove it completely, but some of the tests we have failed after that. Still can't figure out why.

@romani
Copy link
Member

romani commented Apr 1, 2024

as a hack, please make method as public and write junit test for this method to clearly show that survival can gone if we do have explicit test.

@jxr98
Copy link
Contributor Author

jxr98 commented Apr 2, 2024

as a hack, please make method as public and write junit test for this method to clearly show that survival can gone if we do have explicit test.

Thanks. The method is very straightforward containing several or operator as follows
image, and the code is here. From debugging and experience, the survivals are Expr, if, for, return, {, etc. The conditions in the method can't be complete I guess. 🤔

@nrmancuso
Copy link
Member

but some of the tests we have failed after that. Still can't figure out why

If this is true, then we are missing tests from the pitest profile in pom.xml for this check. Please push up your changes and show this failure so that we can help debug.

@jxr98
Copy link
Contributor Author

jxr98 commented Apr 2, 2024

but some of the tests we have failed after that. Still can't figure out why

If this is true, then we are missing tests from the pitest profile in pom.xml for this check. Please push up your changes and show this failure so that we can help debug.

I've pushed the changes I made. If the method just return true directly, the failed tests are shown as in the file below.
com.puppycrawl.tools.checkstyle.checks.coding.VariableDeclarationUsageDistanceCheckTest.txt

It looks like the pom file includes the target class and target test of this check correctly. I'd really appreciate it if you could help me debug. I guess I might make some mistakes where I'm not aware of right now.

@nrmancuso
Copy link
Member

It looks like the pom file includes the target class and target test of this check correctly. I'd really appreciate it if you could help me debug. I guess I might make some mistakes where I'm not aware of right now.

There is definitely something weird going on here. I've checked this code out locally, and tried to hardcode the mutation in a number of ways, but the tests are always failing. The only thing I can think of is that the bytecode inlines this method and the actual mutation isn't what is shown in the suppression.

I suggest that you check the bytecode for this file, you can see how to do this at https://github.com/checkstyle/checkstyle/wiki/How-to-Generate-and-Analyze-Pitest-Reports#decompiler-usage-to-see-bytecode.

@Vyom-Yadav have you seen anything like this before?

@@ -22,8 +22,7 @@ void mm() {
<T> void xx(List<T> m){}
}
public void method9() {
// until https://github.com/checkstyle/checkstyle/issues/13011
Copy link
Member

Choose a reason for hiding this comment

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

First I would confirm that these 2 issues are exactly the same and explain it so we understand. I find it odd that a method issue would fix a class issue, but maybe no one noticed the cases were extremely similar.

Also, apparently you reported both issues. :)

Copy link
Contributor Author

@jxr98 jxr98 Apr 10, 2024

Choose a reason for hiding this comment

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

Oo right they r almost the same.

@@ -784,7 +787,8 @@ private static boolean isZeroDistanceToken(int type) {
|| type == TokenTypes.MODIFIERS
|| type == TokenTypes.RESOURCE
|| type == TokenTypes.EXTENDS_CLAUSE
|| type == TokenTypes.IMPLEMENTS_CLAUSE;
|| type == TokenTypes.IMPLEMENTS_CLAUSE
|| type == TokenTypes.CLASS_DEF;
Copy link
Member

@rnveach rnveach Apr 3, 2024

Choose a reason for hiding this comment

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

removed conditional - replaced equality check with true

This is my local when I run the profile.
Image

I removed one of these lines completely, or something similar to changing || type == TokenTypes.EXTENDS_CLAUSE to || false, and all the tests passed. This shows the mutation. The mutation in this case is reversed from the text that says true.

At a glance this sort of makes sense. extends and implements both have class as a parent.

So now we must identify how to kill these mutations, or understand why they can't be killed. I would look over https://github.com/checkstyle/checkstyle/wiki/How-to-Generate-and-Analyze-Pitest-Reports#how-to-find-java-code-that-can-kill-mutation and https://github.com/checkstyle/contribution/tree/master/checkstyle-tester#checkstyle-pitest-regression for the next steps. You can also look over other pitest issues that describe the more complex process. We do not normally accept new code with new surviving mutations.

Copy link
Member

Choose a reason for hiding this comment

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

At a glance this sort of makes sense. extends and implements both have class as a parent.

Yes, this sounds like what is happening here. We should probably add some test cases for local enums, records, and interfaces as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank u so much!!! I see. Trying to solve it.

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

4 participants