fix : [Rule GCI82] Resolve Bug [#122] : final keyword is not recognized when using instanceof pattern#189
fix : [Rule GCI82] Resolve Bug [#122] : final keyword is not recognized when using instanceof pattern#189arhnabri wants to merge 12 commits into
Conversation
…is not recognized when using instanceof pattern .
…is not recognized when using instanceof pattern .
There was a problem hiding this comment.
Pull request overview
This PR fixes a false positive in rule GCI82 (“The variable is never reassigned and can be 'final'”) where a pattern variable declared with final in an instanceof pattern was still being reported as non-final.
Changes:
- Update GCI82 to determine
final/staticvia the variable symbol (symbol().isFinal()/symbol().isStatic()) instead of relying on syntax modifiers. - Add integration-test cases covering
instanceofpattern variables with/withoutfinaland with reassignment. - Document the fix in the changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/main/java/org/greencodeinitiative/creedengo/java/checks/MakeNonReassignedVariablesConstants.java |
Fixes the detection logic by switching final/static checks to symbol-based evaluation. |
src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java |
Adds test coverage for instanceof pattern variables (including final). |
CHANGELOG.md |
Adds an Unreleased entry referencing issue #122. |
Comments suppressed due to low confidence (2)
src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java:147
- Spelling/casing in this new method name is off ("nonReasigned...Withfinal..."). Please rename to use correct spelling and consistent camelCase (e.g., "nonReassigned...WithFinal...") to keep the test suite readable.
public String nonReasignedVariablewithPatternInstanceOfWithfinalShouldBeCompliant()
{
final String o = "COMPLIANT";
src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/org/greencodeinitiative/creedengo/java/checks/GCI82/MakeNonReassignedVariablesConstants.java:158
- Spelling in this new method name looks incorrect ("reasignedVariable..."). Please rename to "reassigned..." (double 's') to avoid propagating typos in test names.
public String reasignedVariablewithPatternInstanceOfShouldBeCompliant()
{
final String o = "COMPLIANT";
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
#122 resolve bug : final keyword is not recognized when using instanceof pattern