Closed Zuplyx closed 1 year ago
@Zuplyx thank you for the report! It is indeed a bug. Will fix it as soon as possible.
Hi @Zuplyx ! I looked at the issue, and sonar-java does not suggest any fix for it. However, I do agree that is should not produce a non-compilable output.
@khaes-kth any idea what could we do here?
int
as iterator.Do we ever provide a fix that is not dictated in SonarQube? If yes, we could go forward with 1
.
Hi @algomaster99, I would say this is a problem with SonarSource documents and suggestions. I would choose option 2! If we cannot fix the issue using SonarSource suggestions, we don't do it (skip such issues) and mark the processor as incomplete.
with SonarSource documents and suggestions
Opened a bug report here.
I prefer 1
, but I will try to talk to SonarSource about this fix though. Otherwise I will go forward with 2
.
SonarSource updated the documentation for rule S1481.
However, it does not talk about enhanced for-loop at all. Let me ask them about this.
Let me ask them about this.
Great! Let's do it!
Done! See https://community.sonarsource.com/t/s1481-unused-local-variables-should-be-removed-is-wrongly-documented/89427/3?u=aman. Let's wait for their reply.
The repair for rule S1481 creates compile errors when processing local variables in for loops or local variables with writes (see example below). A possible fix for this problem, would be to ignore unused variables in for-loops and to also remove all writes to the unused local variable.
Original Code:
Result after processing with sorald: