[java-inspections] FieldCanBeLocalInspection: do not warn on volatile fields

Somewhat helps IDEA-100902 False warning Field can be converted to a local variable

GitOrigin-RevId: cb6a4c06d8939ef35fbbfbc1a98baabc977fee26
This commit is contained in:
Tagir Valeev
2022-07-11 15:56:32 +00:00
committed by intellij-monorepo-bot
parent 42dc156132
commit 56d1fb8fb1
@@ -52,6 +52,11 @@ public class FieldCanBeLocalInspection extends AbstractBaseJavaLocalInspectionTo
if (!field.isPhysical() || AnnotationUtil.isAnnotated(field, excludeAnnos, 0)) {
continue;
}
if (field.hasModifierProperty(PsiModifier.VOLATILE)) {
// Assume that fields marked as volatile can be modified concurrently
// (e.g. if the only method where they are changed is called from several threads)
continue;
}
if (field.hasModifierProperty(PsiModifier.PRIVATE) && !(field.hasModifierProperty(PsiModifier.STATIC) && field.hasModifierProperty(PsiModifier.FINAL))) {
candidates.add(field);
}