mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ReturnSeparatedFromComputationInspection: do not process if variable and return are in different scopes
Fixes EA-237085 - assert: ControlFlowUtil.isVariableReadInFinally GitOrigin-RevId: 1f48700f3f08faf96f12b440b3fd54d735c50620
This commit is contained in:
committed by
intellij-monorepo-bot
parent
997f2ec6d0
commit
8a830c1018
+6
-1
@@ -69,7 +69,12 @@ public class ReturnSeparatedFromComputationInspection extends AbstractBaseJavaLo
|
||||
final PsiVariable returnedVariable = (PsiVariable)resolved;
|
||||
final PsiCodeBlock variableScope = getVariableScopeBlock(returnedVariable);
|
||||
if (variableScope != null) {
|
||||
return new ReturnContext(returnStatement, returnScope, returnType, refactoredStatement, returnedVariable, variableScope);
|
||||
PsiElement variableMethod = PsiTreeUtil.getParentOfType(variableScope, PsiMethod.class, PsiLambdaExpression.class);
|
||||
PsiElement returnMethod = PsiTreeUtil.getParentOfType(returnScope, PsiMethod.class, PsiLambdaExpression.class);
|
||||
if (variableMethod == returnMethod) {
|
||||
return new ReturnContext(returnStatement, returnScope, returnType, refactoredStatement, returnedVariable,
|
||||
variableScope);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Move 'return' closer to computation of the value of 'x'" "false"
|
||||
class X {
|
||||
int test() {
|
||||
int x = 0;
|
||||
Runnable r = () -> {
|
||||
try {
|
||||
if (r == null) {
|
||||
x = 1;
|
||||
}
|
||||
return <caret>x;
|
||||
}
|
||||
finally {
|
||||
System.out.println(x);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user