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 #11973: Fix NPE on empty switch statements in VariableDeclarati… #12052
Issue #11973: Fix NPE on empty switch statements in VariableDeclarati… #12052
Conversation
c6daab6
to
83e8eb9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see failures in pitest and generate check regression report.
Item:
...ks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistanceDefault.java
Outdated
Show resolved
Hide resolved
@nick-mancuso While attempting to kill the mutation I discovered that the following code does not raise any violations. Shall I make an issue for it? I believe the newfound bug first needs to be fixed before I can proceed with the current issue. int issue11973(int a) {
int sw = 5; // violation 'Distance between variable ''sw'' declaration and its first usage is 2, but allowed 1.'
return switch (a) {
case 0 -> {
a++;
yield sw + a;
}
};
} |
Please make an issue for this, make sure to explain why we need to fix new issue before we complete this PR. |
yes, better to separate issue to be addressed in separate issues/PRs. |
@stoyanK7 , NPE is blocker to use Check at all, can we continue this PR to at least fix NPE and even fine with false positived. Exception - force users to disable Check at all in config. So lets fix exception as primary goal. |
@romani Alright, will focus my attention to fix this NPE :) |
83e8eb9
to
3fc7939
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Items
...ava/com/puppycrawl/tools/checkstyle/checks/coding/VariableDeclarationUsageDistanceCheck.java
Outdated
Show resolved
Hide resolved
3fc7939
to
03490f0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So pitest-coding-1
is going to fail with the following mutation here:
Unnecessary suppressed mutation(s) found and should be removed:
Source File: "VariableDeclarationUsageDistanceCheck.java"
Class: "com.puppycrawl.tools.checkstyle.checks.coding.VariableDeclarationUsageDistanceCheck"
Method: "lambda$getFirstCaseGroupOrSwitchRule$2"
Line Contents: ".orElseGet(() -> block.findFirstToken(TokenTypes.SWITCH_RULE));"
Mutator: "org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator"
Description: "replaced call to com/puppycrawl/tools/checkstyle/api/DetailAST::findFirstToken with receiver"
Can anybody help me and explain what it does(how the code looks after mutation) since documentation is scarce(practically nonexistent).
This is what I could find
I believe the mutation is replacing |
@rnveach Already tried that and |
@stoyanK7 Please read the top of the pitest report from CI.
It means you are now killing this mutation and can remove it from the suppressions. |
@rnveach Oh my god, you are right, thanks! I should have actually read whats up. I assumed it is a surviving one since that was always the case previously, but it turns out pitest also fails when there are unnecessarily suppressed mutations. Removing it right now. |
434d66d
to
40df68e
Compare
...s/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistanceGeneral2.java
Outdated
Show resolved
Hide resolved
4790a3e
to
cc48160
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update documentation for getFirstCaseGroupOrSwitchRule
to mention that we will return null if switch block is empty.
cc48160
to
5ae7d1a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please review drone CI falure:
src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance/InputVariableDeclarationUsageDistanceCheckSwitchExpressions2.java:28: error: yield outside of switch expression
yield 2;
^
item:
...ava/com/puppycrawl/tools/checkstyle/checks/coding/VariableDeclarationUsageDistanceCheck.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
items
...ava/com/puppycrawl/tools/checkstyle/checks/coding/VariableDeclarationUsageDistanceCheck.java
Outdated
Show resolved
Hide resolved
8f631c4
to
b99dd4c
Compare
b99dd4c
to
2e7da62
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Items
...ava/com/puppycrawl/tools/checkstyle/checks/coding/VariableDeclarationUsageDistanceCheck.java
Outdated
Show resolved
Hide resolved
2e7da62
to
3fcdd10
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Items
src/test/java/com/puppycrawl/tools/checkstyle/utils/TokenUtilTest.java
Outdated
Show resolved
Hide resolved
395b380
to
ded47a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Items
final List<String> children = new ArrayList<>(3); | ||
final List<Integer> tokensToMatch = List.of(TokenTypes.CLASS_DEF, TokenTypes.VARIABLE_DEF); | ||
|
||
TokenUtil.forEachChild(astForTest, tokensToMatch, child -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might was no clear. I know it is very unusual and sattle.
We allow tests only by Inputs with embedded config.
All other forms of testing are well proven "way to hell" in our repo .
Please no updates in TokenUtilTest.
Let's come back to "map.or" solution , sorry that we confused you and lost valuable time.
Let me know if you interested in more details why we follow unusual philosophy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inputs with embedded config.
This is not possible here since it is not a check/filter itself.
Please no updates in TokenUtilTest
Let's come back to "map.or" solution
Reverted back. Done.
It's alright. I would not call it wasted time. Dug around the codebase and learned a few things about the rules of this repository and how pull requests should be.
All other forms of testing are well proven "way to hell" in our repo .
Let me know if you interested in more details why we follow unusual philosophy
Yes, I'd like to know why. In my eyes, such a test does not seem harder to maintain than any other check's tests and input files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try our best to use tests only like verifyWithInlineConfigParser(getNonCompilablePath(filename)
.
It makes us confident that we always use compilable input files. And all code in Check can handle any possible-and-compilable combinations of java code and all code in Check are there for a reason (pitest) no extra code and no dead code. Removal/mutation of any part of it immediately detected by Junit tests.
As you might notice in above statement we do not mention about util methods at all , as potentially until method can be copied to class and be part of it. It is our details of implementation that we use util methods, we do not want to let anyone know it, and it subject to change at any time.
If we allow testing of utility methods separately, all logic of all Checks can be generalized and moved to utilities so whole test pressure will also move to utilities. And we will struggle with auto measure of quality of Check.
In result maintainers will win in short term, user will loose in long term, usage will drop, maintainers will not found way to invite new contributions, project is dead eventually.
Right now as you might noticed, new contributor does not need to know all ast and all utilities and all rules. All you need is to put a java file to test and place debug in Check visitToken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We did not born smart, it took us 20 years to do all types of testing to end up where we are. So are of code is still old style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get it now - all in the name of maintainability and keeping the project going and easy to contribute to. Which I have noticed btw.
What does that mean for the util tests though? Do you want them to move over to such testing verifyWithInlineConfigParser
? Is it even possible? Or do you expect tests from checks that use util methods to cover them?
4fe5f6f
to
4dab5af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok to merge
Github, generate report |
OMG, we had exception on project that we in regression list. We might need to have CI script that runs updated in commit check against all such projects to expect no exceptions. CIs are restarted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Item:
...ava/com/puppycrawl/tools/checkstyle/checks/coding/VariableDeclarationUsageDistanceCheck.java
Outdated
Show resolved
Hide resolved
Regression config is missing turning on Also want to remind we are missing checkstyle/contribution#548 from regression config as well |
4dab5af
to
9f80cda
Compare
…onUsageDistance
9f80cda
to
c01689f
Compare
@Vyom-Yadav , please glance at failure |
@romani For nullness checker it is |
@nrmancuso , lets merge this without Checker green state, in worse case we will add one suppression to our files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checker is already unstable, I am fine to merge on red.
Resolves #11973
Diff Regression config: https://gist.githubusercontent.com/stoyanK7/c67715129a58ae4891e4311252de8ea2/raw/01e5f6b1844ceef6fab5c7f14030ecfa12281f48/config.xml