-
Notifications
You must be signed in to change notification settings - Fork 47
Description
Describe the bug
Several case of false detection for rule "The variable is never reassigned and can be 'final'" (GCI82).
In addition to the issues: #121 and #122
To Reproduce
Analyze this open source project : https://github.com/tonikelope/megabasterd
Expected behavior
As written here and here, I expected the rule to detect all variables eligible to be declared as a constant (with final or static final keywords) because this avoids initializing a variable with the same value each time a method is called.
But this rule, implemented as is today, adds a lot of code smell that I don't find relevant (or I need further explanation to understand their relevance):
- Add the 'final' keyword to a method parameter or constructor
- Add the 'final' keyword to a parameter inside a catch
- Add the 'final' keyword to a variable which is initialized in a method when the value is not reassigned BUT the value is not the same between 2 calls method
👉 I can understand the interest to add the 'final' keyword to declare a better intention, but I don't see how adding the final keyword would make the code more sustainable.
Screenshots
- On constructor parameter:
- On method parameter:
- Inside a catch :
- Initializing a variable in a method from another variable:
- Initialization of a local variable in a method which is an array that will have different contents each time the method is called:
- Initializing a class attribute of a parent class:
Software Versions
- SonarQube Version: Community Build v25.8.0.112029
- Plugin Version: 2.1.1