-
-
Notifications
You must be signed in to change notification settings - Fork 65
Gci82 #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zizou-ben
wants to merge
5
commits into
green-code-initiative:main
Choose a base branch
from
JulienSamson-dev:GCI82
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Gci82 #185
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
abef8fe
GCI82- without tests
Ghaith-kh eb2f123
GCI82 tests
Ghaith-kh b65e0f9
GCI82 tests
Ghaith-kh 7f43415
GCI82: fix test - declare Object o as final to avoid false trigger
1915e3c
Merge branch 'green-code-initiative:main' into GCI82
zizou-ben File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the issue is to detect the type pattern variable when it's finak in order to not trigger an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
En Java, le pattern matching pour instanceof (JEP 394, finalisé en JDK 16) introduit la notion de pattern variable, qui est sémantiquement traitée comme une variable locale au sens de la JLS §14.30.1. Comme toute variable locale, elle peut recevoir les modificateurs autorisés sur les locales — dont final — qui sont définis par la JLS §4.12.4 comme une contrainte vérifiée à la compilation (interdiction de réassigner après l'initialisation). Du côté JVM, la JVMS §2.6.1 décrit le tableau des variables locales d'une stack frame comme stockant uniquement des slots typés indexés, sans aucun flag de modificateur. La JVMS §4.7.13 (attribut LocalVariableTable) confirme explicitement la structure du class file pour les variables locales : start_pc, length, name_index, descriptor_index, index — aucun champ access_flags n'existe pour les variables locales, contrairement aux classes, champs et méthodes. Conséquence directe et vérifiable : compiler if (o instanceof String s) et if (o instanceof final String s) produit strictement le même bytecode ; la présence de final ne se traduit par aucun octet supplémentaire ni aucune information runtime, donc zéro impact mémoire, zéro impact CPU à l'exécution. Pousser un développeur à ajouter final sur une pattern variable est donc une modification de code source à coût énergétique runtime nul — exactement ce qu'un linter Green Code doit éviter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conclusion :
Le gain runtime côté application est nul, donc appliquer la règle aux pattern variables n’a pas de valeur Green IT mesurable. Par conséquent, éviter complètement leur analyse est plus cohérent sémantiquement et plus efficace algorithmiquement pour l’analyseur.