Skip to content

Commit

Permalink
SONARJAVA-1400 Proper support of postfix operators
Browse files Browse the repository at this point in the history
  • Loading branch information
benzonico committed Nov 26, 2015
1 parent b6dc73e commit 6e95154
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.sonar.plugins.java.api.tree.NewClassTree;
import org.sonar.plugins.java.api.tree.Tree;
import org.sonar.plugins.java.api.tree.TypeCastTree;
import org.sonar.plugins.java.api.tree.UnaryExpressionTree;
import org.sonar.plugins.java.api.tree.VariableTree;
import org.sonar.plugins.java.api.tree.WhileStatementTree;

Expand Down Expand Up @@ -446,7 +447,15 @@ private void executeUnaryExpression(Tree tree) {
programState = unstackUnary.a;
SymbolicValue unarySymbolicValue = constraintManager.createSymbolicValue(tree);
unarySymbolicValue.computedFrom(unstackUnary.b);
programState = programState.stackValue(unarySymbolicValue);
if(tree.is(Tree.Kind.POSTFIX_DECREMENT, Tree.Kind.POSTFIX_INCREMENT, Tree.Kind.PREFIX_DECREMENT, Tree.Kind.PREFIX_DECREMENT)
&& ((UnaryExpressionTree) tree).expression().is(Tree.Kind.IDENTIFIER)) {
programState = programState.put(((IdentifierTree) ((UnaryExpressionTree) tree).expression()).symbol(), unarySymbolicValue);
}
if(tree.is(Tree.Kind.POSTFIX_DECREMENT, Tree.Kind.POSTFIX_INCREMENT)) {
programState = programState.stackValue(unstackUnary.b.get(0));
} else {
programState = programState.stackValue(unarySymbolicValue);
}
}

private void executeIdentifier(IdentifierTree tree) {
Expand Down
11 changes: 11 additions & 0 deletions java-squid/src/test/files/se/Reproducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,15 @@ public void continue_foreach(boolean a, boolean b, Map<String, String> map) {
}
}

private void increment(int index, int index2) {
int start = index;
index++;
if(start == index) {

}
start = index2;
if(start == index2++) { // Noncompliant
}
}

}

0 comments on commit 6e95154

Please sign in to comment.