mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IdempotentLoopBody: disable for volatile reads
GitOrigin-RevId: 27aa820f0311844e7fd4a23daa2e306e2f6bae9d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2c499916f6
commit
70a61859ea
@@ -63,7 +63,8 @@ public class IdempotentLoopBodyInspection extends AbstractBaseJavaLocalInspectio
|
||||
Collection<PsiVariable> variables = ControlFlowUtil.getWrittenVariables(bodyFlow, 0, bodyFlow.getSize(), true);
|
||||
if (variables.isEmpty()) return;
|
||||
List<PsiReferenceExpression> reads = ControlFlowUtil.getReadBeforeWrite(bodyFlow);
|
||||
if (StreamEx.of(reads).map(PsiReferenceExpression::resolve).select(PsiVariable.class).noneMatch(variables::contains)) {
|
||||
if (StreamEx.of(reads).map(PsiReferenceExpression::resolve).select(PsiVariable.class)
|
||||
.noneMatch(v -> v.hasModifierProperty(PsiModifier.VOLATILE) || variables.contains(v))) {
|
||||
holder.registerProblem(loop.getFirstChild(), JavaBundle.message("inspection.idempotent.loop.body"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,4 +54,14 @@ class IdempotentLoopBody {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
volatile int x;
|
||||
|
||||
int testVolatile() {
|
||||
while(true) {
|
||||
int localX = x;
|
||||
if (localX > 0) return localX;
|
||||
if (localX % 2 == 0) return localX / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user