DfaMemoryStateImpl: fix possible ClassCastException

This commit is contained in:
Tagir Valeev
2018-11-28 12:33:17 +07:00
parent 7ff46eaca8
commit 4d5cc1509f
3 changed files with 12 additions and 1 deletions
@@ -235,7 +235,10 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
setVariableState(var, state.withFacts(facts));
SpecialFieldValue specialFieldValue = facts.get(DfaFactType.SPECIAL_FIELD_VALUE);
if (specialFieldValue != null) {
setVarValue((DfaVariableValue)specialFieldValue.getField().createValue(myFactory, var), specialFieldValue.toConstant(myFactory));
DfaValue targetSpecialField = specialFieldValue.getField().createValue(myFactory, var);
if (targetSpecialField instanceof DfaVariableValue) {
setVarValue((DfaVariableValue)targetSpecialField, specialFieldValue.toConstant(myFactory));
}
}
}
else if (DfaUtil.isComparedByEquals(value.getType()) && !DfaUtil.isComparedByEquals(var.getType())) {
@@ -0,0 +1,7 @@
final class MyClass {
static final int[] arr = {1,2,3};
void test() {
<error descr="Cannot assign a value to final variable 'arr'">arr</error> = new int[] {4};
}
}
@@ -670,4 +670,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
public void testNotNullAnonymousConstructor() { doTest(); }
public void testCaughtNPE() { doTest(); }
public void testTernaryNullability() { doTest(); }
public void testRewriteFinal() { doTest(); }
}