Issue #15058: New Check UnusedCatchParameterShouldBeUnnamed#15358
Conversation
ad85082 to
c50d036
Compare
|
github, generate site |
nrmancuso
left a comment
There was a problem hiding this comment.
Item to discuss before anything else:
| */ | ||
| private void checkIdentifier(DetailAST identAst) { | ||
| if (catchParameter != null | ||
| && !isLeftHandSideValue(identAst) |
There was a problem hiding this comment.
So we don't count reassignment as usage? Judging by the test cases below, we currently do. What am I missing?
There was a problem hiding this comment.
Yes we don't count reassignment as usage. here is its test case :
Judging by the test cases below, we currently do.
can you point to this?
There was a problem hiding this comment.
Note I don't consider the test case below to be a reassignment.
There was a problem hiding this comment.
#15358 (comment) is weird to me.If we were to make e unnamed, we would have to remove this reassignment (even though it does nothing). I suppose I am good with this, let's get this check into the hands of users and go from there.
There was a problem hiding this comment.
Leaving this one unresolved so others can see.
e7960cb to
c566762
Compare
a1da5b6 to
f4c2b67
Compare
|
github, generate report |
f4c2b67 to
052fb36
Compare
nrmancuso
left a comment
There was a problem hiding this comment.
I have spot checked the report, there is far too many violations to check all of them. This is a good first implementation that we can build on, let's get this check into the hands of users.
Great work!
f0efbb8 to
be69edc
Compare
|
github, generate report |
|
@rnveach @nrmancuso do we agree to suppress this? adding a non-nullity condition will be a surviving mutation |
e146622 to
bd7624c
Compare
We can probably make all static analysis happy and also be a bit more expressive: final Optional<CatchParameterDetails> unusedCatchParameter = Optional.ofNullable(catchParameters.peek())
.filter(p -> !"_".equals(p.getName()))
.filter(p -> !p.isUsed());
unusedCatchParameter.ifPresent(catchParameterDetails ->
log(catchParameterDetails.getParameterDefinition(),
MSG_UNUSED_CATCH_PARAMETER,
catchParameterDetails.getName())); |
bd7624c to
f86a9b0
Compare
0d4cf07 to
4867842
Compare
|
@rnveach ping |
c70de7d to
66e0f2a
Compare
66e0f2a to
771eae7
Compare
|
Rebasing to ensure no issues on merge. |
|
checkstyle/contribution#883 (comment) is needed for a merge |
|
@rnveach done |
closes #15058
New module config: https://gist.githubusercontent.com/mahfouz72/afd57aa6e51ca161b7927acd959e5211/raw/3290828c8bb75105d18940f38a97265806b6a8bb/check.xml