Issue #15059: New Check UnusedLambdaParameterShouldBeUnnamed#15480
Conversation
f2b8456 to
9ee24f0
Compare
|
github, generate site |
9ee24f0 to
ca17d06
Compare
Please share in comment, violations on our code, we should recheck if all of them are valid. |
I checked most of them, and they are valid |
Can we simply state |
| unnecessary.semicolon=Лишняя точка с запятой. | ||
| unused.catch.parameter=Неиспользуемый параметр catch ''{0}'' должен быть безымянным. | ||
| unused.lambda.parameter=Неиспользуемый лямбда-параметр ''{0}'' не должен быть назван. | ||
| unused.local.var=Неиспользуемая локальная переменная ''{0}''. |
There was a problem hiding this comment.
Неиспользуемый лямбда-параметр ''{0}'' должен быть безымянным
No, this is not accurate, though they were not called “unnamed” until now. You could use an underscore as a lambda parameter name in Java 8. |
|
You can't use this check on java 8 because unnamed variables concept was not as it is now(21). underscore variable in java 8 can be read from or write to so there will be no benefits if we changed the variable name from 'a' to '_' both can be used as normal identifier in java 8 and below. the rationale of the check is to declare the unused parameter as unnamed because if we are java 21+ we are sure that this unnamed variable can't be used and we want to communicate this explicitly to readers |
please rephase, I do not understand this sentence. What we have in comment of config and in web site is different and I just try to point that better to align wording. In our config comment, we should simply state that we need to enable it only after migration to 21. No need to mention all other nuances. |
nrmancuso
left a comment
There was a problem hiding this comment.
Looks good, few minor things:
| public void leaveToken(DetailAST ast) { | ||
| if (ast.getType() == TokenTypes.LAMBDA) { | ||
| // when leaving a given lambda, check every parameter associated with it | ||
| while (!lambdaParameters.isEmpty() |
There was a problem hiding this comment.
| while (!lambdaParameters.isEmpty() | |
| while (lambdaParameters.peek() != null |
This will make checker happy
There was a problem hiding this comment.
but still checker fails I have no idea how is that possible. may be a false positive? are we ok to suppress?
There was a problem hiding this comment.
| while (!lambdaParameters.isEmpty() | |
| && ast.equals(lambdaParameters.peek().enclosingLambda())) { |
Would this make checker happy?
There was a problem hiding this comment.
No. very weird
while (lambdaParameters.peek() != null
&& ast.equals(lambdaParameters.peek().enclosingLambda)) { ... } <checkerFrameworkError unstable="false">
<fileName>src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/UnusedLambdaParameterShouldBeUnnamedCheck.java</fileName>
<specifier>dereference.of.nullable</specifier>
<message>dereference of possibly-null reference lambdaParameters.peek()</message>
<lineContent>&& ast.equals(lambdaParameters.peek().enclosingLambda)) {</lineContent>
</checkerFrameworkError>There was a problem hiding this comment.
I am good to suppress this, we should also open a bug report with checker
There was a problem hiding this comment.
Leaving this unresolved for the next reviewers to see.
There was a problem hiding this comment.
ca17d06 to
2b54a90
Compare
I just was trying to say that this check can't be used for source code that is below Jdk 8. In Java 8 and earlier versions, the underscore
make sense, done |
|
i am good for your fixes on my comments. I will review this PR at the most end. But I generally good with new Check. |
2b54a90 to
4c00eee
Compare
|
github, generate site |
4c00eee to
1143b5c
Compare
nrmancuso
left a comment
There was a problem hiding this comment.
Very good, thanks for making this an easy review :)
1143b5c to
602de17
Compare
|
github, generate report |
88a6577 to
dabbef2
Compare
dabbef2 to
c7fe71a
Compare
|
github, generate site |
56be48a to
cf800d1
Compare
cf800d1 to
428da11
Compare

closes #15059:
New module config: https://gist.githubusercontent.com/mahfouz72/afd57aa6e51ca161b7927acd959e5211/raw/3e297236fff03643bdcffa607b54b528b3438ece/check.xml