Skip to content

fix : [Rule GCI82] Resolve Bug [#122] : final keyword is not recognized when using instanceof pattern#189

Open
arhnabri wants to merge 12 commits into
green-code-initiative:mainfrom
arhnabri:main
Open

fix : [Rule GCI82] Resolve Bug [#122] : final keyword is not recognized when using instanceof pattern#189
arhnabri wants to merge 12 commits into
green-code-initiative:mainfrom
arhnabri:main

Conversation

@arhnabri
Copy link
Copy Markdown

#122 resolve bug : final keyword is not recognized when using instanceof pattern

…is not recognized when using instanceof pattern .
…is not recognized when using instanceof pattern .
@arhnabri arhnabri changed the title [Rule GCI82] Resolve Bug [#122] : final keyword is not recognized when using instanceof pattern fix : [Rule GCI82] Resolve Bug [#122] : final keyword is not recognized when using instanceof pattern May 19, 2026
@arhnabri arhnabri requested a review from dedece35 May 19, 2026 15:24
@arhnabri arhnabri added 🗃️ rule rule improvment or rule development or bug 💉 bug Something isn't working labels May 19, 2026
@dedece35 dedece35 requested a review from Copilot May 19, 2026 15:25
@arhnabri arhnabri removed the 🗃️ rule rule improvment or rule development or bug label May 19, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/static via the variable symbol (symbol().isFinal() / symbol().isStatic()) instead of relying on syntax modifiers.
  • Add integration-test cases covering instanceof pattern variables with/without final and 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.

@arhnabri arhnabri self-assigned this May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🏆 challenge 🏆 Work done during the Green Code Challenge 💉 bug Something isn't working

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants