@Override public void computedFrom(List<ProgramState.SymbolicValueSymbol> symbolicValues) { Preconditions.checkArgument(symbolicValues.size() == 1); this.operand = symbolicValues.get(0).symbolicValue(); this.operandSymbol = symbolicValues.get(0).symbol(); }
@Override public void computedFrom(List<ProgramState.SymbolicValueSymbol> symbolicValues) { Preconditions.checkArgument(symbolicValues.size() == 2); Preconditions.checkState(leftOp == null && rightOp == null, "Operands already set!"); rightOp = symbolicValues.get(0).symbolicValue(); rightSymbol = symbolicValues.get(0).symbol(); leftOp = symbolicValues.get(1).symbolicValue(); leftSymbol = symbolicValues.get(1).symbol(); }
@Override public void computedFrom(List<ProgramState.SymbolicValueSymbol> symbolicValues) { Preconditions.checkArgument(symbolicValues.size() == 1); this.operand = symbolicValues.get(0).symbolicValue(); this.operandSymbol = symbolicValues.get(0).symbol(); }
private static Set<Flow> flowsForMethodArguments(ExplodedGraph.Node node, MethodInvocationTree mit, int parameterCausingExceptionIndex) { ProgramState programState = node.programState; List<ProgramState.SymbolicValueSymbol> arguments = Lists.reverse(programState.peekValuesAndSymbols(mit.arguments().size())); SymbolicValue parameterCausingExceptionSV = arguments.get(parameterCausingExceptionIndex).symbolicValue(); Set<SymbolicValue> argSymbolicValues = new LinkedHashSet<>(); Set<Symbol> argSymbols = new LinkedHashSet<>(); arguments.stream() .filter(svs -> parameterCausingExceptionSV == svs.symbolicValue() || hasConstraintOtherThanNonNull(svs, programState)) .forEach(svs -> { argSymbolicValues.add(svs.symbolicValue()); Symbol symbol = svs.symbol(); if (symbol != null) { argSymbols.add(symbol); } }); List<Class<? extends Constraint>> domains = domainsFromArguments(programState, argSymbolicValues); return FlowComputation.flow(node, argSymbolicValues, c -> true, c -> false, domains, argSymbols); }
@Override public void visitAssignmentExpression(AssignmentExpressionTree tree) { SymbolicValue var; SymbolicValue expr; Symbol symbol; if (ExpressionUtils.isSimpleAssignment(tree)) { symbol = ExpressionUtils.extractIdentifier(tree).symbol(); var = programState.getValue(symbol); expr = programState.peekValue(); } else { ProgramState.Pop unstackValue = programState.unstackValue(2); var = unstackValue.values.get(1); expr = unstackValue.values.get(0); symbol = unstackValue.valuesAndSymbols.get(0).symbol(); } checkExpression(tree, var, expr, symbol); }
private static Set<Flow> flowsForMethodArguments(ExplodedGraph.Node node, MethodInvocationTree mit, int parameterCausingExceptionIndex) { ProgramState programState = node.programState; List<ProgramState.SymbolicValueSymbol> arguments = Lists.reverse(programState.peekValuesAndSymbols(mit.arguments().size())); SymbolicValue parameterCausingExceptionSV = arguments.get(parameterCausingExceptionIndex).symbolicValue(); Set<SymbolicValue> argSymbolicValues = new LinkedHashSet<>(); Set<Symbol> argSymbols = new LinkedHashSet<>(); arguments.stream() .filter(svs -> parameterCausingExceptionSV == svs.symbolicValue() || hasConstraintOtherThanNonNull(svs, programState)) .forEach(svs -> { argSymbolicValues.add(svs.symbolicValue()); Symbol symbol = svs.symbol(); if (symbol != null) { argSymbols.add(symbol); } }); List<Class<? extends Constraint>> domains = domainsFromArguments(programState, argSymbolicValues); return FlowComputation.flow(node, argSymbolicValues, c -> true, c -> false, domains, argSymbols); }
private void handleAssignment(CheckerContext context, AssignmentExpressionTree assignmentExpressionTree) { SymbolicValueSymbol assignedVariable = context.getState().peekValueSymbol(); Symbol assignedSymbol = assignedVariable.symbol(); if (assignedSymbol == null // Rule S3959 returns the same SV after each intermediate operations, // meaning that 'stream = stream.map(...);' would be detected as redundant assignment if not explicitly excluded || STREAM_TYPES.stream().anyMatch(assignedSymbol.type()::is)) { return; } ExplodedGraph.Node node = context.getNode(); ProgramState previousState = node.programState; SymbolicValue oldValue = previousState.getValue(assignedSymbol); SymbolicValue newValue = assignedVariable.symbolicValue(); Symbol fromSymbol = previousState.peekValueSymbol().symbol(); assignmentsByMethod.peek().put(assignmentExpressionTree, new AssignmentDataHolder(assignedSymbol, oldValue, newValue, fromSymbol, node)); }
@Override public void visitAssignmentExpression(AssignmentExpressionTree tree) { SymbolicValue var; SymbolicValue expr; Symbol symbol; if (ExpressionUtils.isSimpleAssignment(tree)) { symbol = ExpressionUtils.extractIdentifier(tree).symbol(); var = programState.getValue(symbol); expr = programState.peekValue(); } else { ProgramState.Pop unstackValue = programState.unstackValue(2); var = unstackValue.values.get(1); expr = unstackValue.values.get(0); symbol = unstackValue.valuesAndSymbols.get(0).symbol(); } checkExpression(tree, var, expr, symbol); }
@Override public void visitBinaryExpression(BinaryExpressionTree tree) { switch (tree.kind()) { case MULTIPLY: case PLUS: case MINUS: case DIVIDE: case REMAINDER: ProgramState.Pop unstackValue = programState.unstackValue(2); checkExpression(tree, unstackValue.values.get(1), unstackValue.values.get(0), unstackValue.valuesAndSymbols.get(0).symbol()); break; default: // do nothing } }
private void handleAssignment(CheckerContext context, AssignmentExpressionTree assignmentExpressionTree) { SymbolicValueSymbol assignedVariable = context.getState().peekValueSymbol(); Symbol assignedSymbol = assignedVariable.symbol(); if (assignedSymbol == null // Rule S3959 returns the same SV after each intermediate operations, // meaning that 'stream = stream.map(...);' would be detected as redundant assignment if not explicitly excluded || STREAM_TYPES.stream().anyMatch(assignedSymbol.type()::is)) { return; } ExplodedGraph.Node node = context.getNode(); ProgramState previousState = node.programState; SymbolicValue oldValue = previousState.getValue(assignedSymbol); SymbolicValue newValue = assignedVariable.symbolicValue(); Symbol fromSymbol = previousState.peekValueSymbol().symbol(); assignmentsByMethod.peek().put(assignmentExpressionTree, new AssignmentDataHolder(assignedSymbol, oldValue, newValue, fromSymbol, node)); }
@Override public void visitBinaryExpression(BinaryExpressionTree tree) { switch (tree.kind()) { case MULTIPLY: case PLUS: case MINUS: case DIVIDE: case REMAINDER: ProgramState.Pop unstackValue = programState.unstackValue(2); checkExpression(tree, unstackValue.values.get(1), unstackValue.values.get(0), unstackValue.valuesAndSymbols.get(0).symbol()); break; default: // do nothing } }
private Set<Symbol> getReturnSymbolAsTrackedSymbols(List<Integer> parameterIndices) { if (parameterIndices.contains(-1) && node.programState.peekValue() == node.programState.exitValue()) { Symbol symbol = node.programState.peekValueSymbol().symbol(); if (symbol != null) { return Collections.singleton(symbol); } } return Collections.emptySet(); }
private boolean shouldWrapArgument(ProgramState.SymbolicValueSymbol argument, ExpressionTree argumentTree) { ResourceConstraint argConstraint = programState.getConstraint(argument.symbolicValue(), ResourceConstraint.class); return (argConstraint == OPEN && argument.symbol() != null) || (argConstraint == null && isCloseable(argumentTree)); }
private Set<Symbol> getReturnSymbolAsTrackedSymbols(List<Integer> parameterIndices) { if (parameterIndices.contains(-1) && node.programState.peekValue() == node.programState.exitValue()) { Symbol symbol = node.programState.peekValueSymbol().symbol(); if (symbol != null) { return Collections.singleton(symbol); } } return Collections.emptySet(); }
private boolean shouldWrapArgument(ProgramState.SymbolicValueSymbol argument, ExpressionTree argumentTree) { ResourceConstraint argConstraint = programState.getConstraint(argument.symbolicValue(), ResourceConstraint.class); return (argConstraint == OPEN && argument.symbol() != null) || (argConstraint == null && isCloseable(argumentTree)); }
@Override public void computedFrom(List<ProgramState.SymbolicValueSymbol> symbolicValues) { Preconditions.checkArgument(symbolicValues.size() == 2); Preconditions.checkState(leftOp == null && rightOp == null, "Operands already set!"); rightOp = symbolicValues.get(0).symbolicValue(); rightSymbol = symbolicValues.get(0).symbol(); leftOp = symbolicValues.get(1).symbolicValue(); leftSymbol = symbolicValues.get(1).symbol(); }