mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
effectively final check (IDEA-128196)
This commit is contained in:
+10
-7
@@ -696,14 +696,17 @@ public class HighlightControlFlowUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ControlFlowUtil.isVariableDefinitelyAssigned(variable, controlFlow)) {
|
||||
final Collection<ControlFlowUtil.VariableInfo> initializedTwice = ControlFlowUtil.getInitializedTwice(controlFlow);
|
||||
effectivelyFinal = !initializedTwice.contains(new ControlFlowUtil.VariableInfo(variable, null));
|
||||
if (effectivelyFinal) {
|
||||
effectivelyFinal = notAccessedForWriting(variable, new LocalSearchScope(scope));
|
||||
final List<PsiReferenceExpression> readBeforeWriteLocals = ControlFlowUtil.getReadBeforeWriteLocals(controlFlow);
|
||||
for (PsiReferenceExpression expression : readBeforeWriteLocals) {
|
||||
if (expression.resolve() == variable) {
|
||||
return PsiUtil.isAccessedForReading(expression);
|
||||
}
|
||||
} else {
|
||||
effectivelyFinal = false;
|
||||
}
|
||||
|
||||
final Collection<ControlFlowUtil.VariableInfo> initializedTwice = ControlFlowUtil.getInitializedTwice(controlFlow);
|
||||
effectivelyFinal = !initializedTwice.contains(new ControlFlowUtil.VariableInfo(variable, null));
|
||||
if (effectivelyFinal) {
|
||||
effectivelyFinal = notAccessedForWriting(variable, new LocalSearchScope(scope));
|
||||
}
|
||||
}
|
||||
return effectivelyFinal;
|
||||
|
||||
+15
-1
@@ -39,7 +39,7 @@ public class XXX {
|
||||
void m3(int x, boolean cond) {
|
||||
int y;
|
||||
if (cond) y = 1;
|
||||
foo(() -> x+<error descr="Variable used in lambda expression should be effectively final">y</error>);
|
||||
foo(() -> x+<error descr="Variable 'y' might not have been initialized">y</error>);
|
||||
}
|
||||
|
||||
void m4(int x, boolean cond) {
|
||||
@@ -128,3 +128,17 @@ class IDEA114737 {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class IDEA128196 {
|
||||
void a() {
|
||||
int value;
|
||||
|
||||
try {
|
||||
value = 1;
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
|
||||
new Thread(() -> System.out.println(value));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user