[java-dfa] Fix false-positive at array initialization

GitOrigin-RevId: b36b1373c6f7691af6dd129d80bf250a3d833727
This commit is contained in:
Tagir Valeev
2021-04-29 05:18:38 +00:00
committed by intellij-monorepo-bot
parent c47b9c9e4f
commit 3aa97e08fa
3 changed files with 9 additions and 4 deletions
@@ -1841,10 +1841,7 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
if (val instanceof Integer) {
int lengthValue = (Integer)val;
if (lengthValue > 0 && lengthValue <= MAX_UNROLL_SIZE) {
DfaVariableValue var = getTargetVariable(arrayExpression);
if (var == null) {
var = createTempVariable(type);
}
DfaVariableValue var = createTempVariable(type);
addInstruction(new PushInstruction(var, null, true));
addInstruction(new SwapInstruction());
addInstruction(new AssignInstruction(null, var));
@@ -0,0 +1,7 @@
public class InitArrayInConstructor {
double[] arr;
InitArrayInConstructor() {
arr = new double[3];
}
}
@@ -698,4 +698,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
public void testBoxedDivisionComparison() { doTest(); }
public void testUnknownComparedToNullable() { doTest(); }
public void testCastInCatch() { doTest(); }
public void testInitArrayInConstructor() { doTest(); }
}