Skip to content

Commit e074e6d

Browse files
committed
SONARJAVA-1391 Rely on symbolic value on stack rather than symbol
Relying on symbols lead to trouble when symbol is unknown. It is better to rely on the symbolic value wee already created and is available on the stack
1 parent daa6cbf commit e074e6d

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

java-squid/src/main/java/org/sonar/java/se/ExplodedGraphWalker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,11 @@ private void executeLogicalAssignement(AssignmentExpressionTree tree) {
455455
ExpressionTree variable = tree.variable();
456456
if (variable.is(Tree.Kind.IDENTIFIER)) {
457457
ProgramState.Pop unstack = programState.unstackValue(2);
458+
SymbolicValue assignedTo = unstack.values.get(0);
458459
SymbolicValue value = unstack.values.get(1);
459460
programState = unstack.state;
460461
SymbolicValue symbolicValue = constraintManager.createSymbolicValue(tree);
461-
symbolicValue.computedFrom(ImmutableList.of(programState.getValue(((IdentifierTree) variable).symbol()), value));
462+
symbolicValue.computedFrom(ImmutableList.of(assignedTo, value));
462463
programState = programState.put(((IdentifierTree) variable).symbol(), symbolicValue);
463464
programState = programState.stackValue(symbolicValue);
464465
}

java-squid/src/test/files/se/Reproducer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,8 @@ void foo() {
112112
object2.toString(); // not accessible with null value
113113
}
114114

115+
void assignUnknownSymbol() {
116+
unknown |= false;
117+
}
118+
115119
}

0 commit comments

Comments
 (0)