mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ControlFlowAnalyzer: Enable math evaluation in for loop initializer
Fixes IDEA-195855 Incorrect NPE warning in reversed indexed for loop
This commit is contained in:
+5
-1
@@ -1388,7 +1388,11 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
if (parent instanceof PsiBinaryExpression && RelationType.fromElementType(((PsiBinaryExpression)parent).getOperationTokenType()) != null) {
|
||||
return true;
|
||||
}
|
||||
if (parent instanceof PsiLoopStatement) return false;
|
||||
if (parent instanceof PsiLoopStatement &&
|
||||
!(parent instanceof PsiForStatement &&
|
||||
PsiTreeUtil.isAncestor(((PsiForStatement)parent).getInitialization(), expression, false))) {
|
||||
return false;
|
||||
}
|
||||
parent = parent.getParent();
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -202,4 +202,16 @@ public class LongRangeBasics {
|
||||
System.out.println(s2.<warning descr="Method invocation 'trim' may produce 'java.lang.NullPointerException'">trim</warning>());
|
||||
}
|
||||
}
|
||||
|
||||
void testLoopInitializer(List l) {
|
||||
int count = l != null ? l.size() : 0;
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
try {
|
||||
Object o = l.get(i);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user