use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ExplodedGraphWalker method executeNewClass.
private void executeNewClass(NewClassTree tree) {
NewClassTree newClassTree = tree;
programState = programState.unstackValue(newClassTree.arguments().size()).state;
// Enqueue exceptional paths
((CFG.Block) node.programPoint.block).exceptions().forEach(b -> enqueue(new ProgramPoint(b), programState, !b.isCatchBlock()));
SymbolicValue svNewClass = constraintManager.createSymbolicValue(newClassTree);
programState = programState.stackValue(svNewClass);
programState = svNewClass.setSingleConstraint(programState, ObjectConstraint.NOT_NULL);
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ExplodedGraphWalker method executeVariable.
/**
* @see JLS8 4.12.5 for details
*/
private void executeVariable(VariableTree variableTree, @Nullable Tree terminator) {
Symbol variableSymbol = variableTree.symbol();
if (variableTree.initializer() == null) {
SymbolicValue sv = null;
if (terminator != null && terminator.is(Tree.Kind.FOR_EACH_STATEMENT)) {
sv = constraintManager.createSymbolicValue(variableTree);
if (isAnnotatedNonNull(variableSymbol)) {
programState = programState.addConstraint(sv, ObjectConstraint.NOT_NULL);
}
} else if (variableTree.parent().is(Tree.Kind.CATCH)) {
sv = handleCatchVariable(variableSymbol.type());
// an exception have been thrown and caught, stack must be cleared
// see notes in JVMS 8 - ยง6.5. - instruction "athrow"
programState = programState.clearStack();
// exception variable is not null by definition
programState = programState.addConstraint(sv, ObjectConstraint.NOT_NULL);
}
if (sv != null) {
programState = programState.put(variableSymbol, sv);
}
} else {
ProgramState.Pop unstack = programState.unstackValue(1);
programState = unstack.state;
programState = programState.put(variableSymbol, unstack.values.get(0));
}
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ExplodedGraphWalker method executeMemberSelect.
private void executeMemberSelect(MemberSelectExpressionTree mse) {
if (!"class".equals(mse.identifier().name())) {
ProgramState.Pop unstackMSE = programState.unstackValue(1);
programState = unstackMSE.state;
}
if (ExpressionUtils.isSelectOnThisOrSuper(mse)) {
executeIdentifier(mse.identifier());
} else {
SymbolicValue mseValue = constraintManager.createSymbolicValue(mse);
programState = programState.stackValue(mseValue);
}
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ExplodedGraphWalker method handleCatchVariable.
private SymbolicValue handleCatchVariable(Type caughtType) {
SymbolicValue peekValue = programState.peekValue();
SymbolicValue.ExceptionalSymbolicValue sv = null;
Type exceptionType = null;
// FIXME SONARJAVA-2069 every path conducting to a catch block should have an exceptional symbolic value on top of the stack
if (peekValue instanceof SymbolicValue.ExceptionalSymbolicValue) {
sv = (SymbolicValue.ExceptionalSymbolicValue) peekValue;
exceptionType = sv.exceptionType();
}
if (exceptionType == null || exceptionType.isUnknown()) {
// unknown exception, create an exception of the adequate type
sv = constraintManager.createExceptionalSymbolicValue(caughtType);
}
// use a dedicated SV encapsulating the caught exception
return constraintManager.createCaughtExceptionSymbolicValue(sv);
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class FlowComputation method flow.
private static Set<Flow> flow(ExplodedGraph.Node currentNode, Set<SymbolicValue> symbolicValues, Predicate<Constraint> addToFlow, Predicate<Constraint> terminateTraversal, List<Class<? extends Constraint>> domains, Set<Symbol> symbols, boolean skipExceptionMessages) {
Set<SymbolicValue> allSymbolicValues = symbolicValues.stream().map(FlowComputation::computedFrom).flatMap(Set::stream).collect(Collectors.toSet());
PSet<Symbol> trackedSymbols = PCollections.emptySet();
for (Symbol symbol : symbols) {
trackedSymbols = trackedSymbols.add(symbol);
}
if (symbols.isEmpty()) {
for (SymbolicValue symbolicValue : symbolicValues) {
for (Symbol symbol : symbolicValue.computedFromSymbols()) {
trackedSymbols = trackedSymbols.add(symbol);
}
}
}
FlowComputation flowComputation = new FlowComputation(allSymbolicValues, addToFlow, terminateTraversal, domains, skipExceptionMessages);
return flowComputation.run(currentNode, trackedSymbols);
}
Aggregations