private static boolean isPipelineConsumed(ProgramState programState, SymbolicValue symbolicValue) { StreamPipelineConstraint constraint = programState.getConstraint(symbolicValue, StreamPipelineConstraint.class); return constraint == StreamPipelineConstraint.CONSUMED; }
private boolean passedCloseableParameter(SymbolicValue resource) { return resource instanceof ResourceWrapperSymbolicValue && programState.getConstraint(((ResourceWrapperSymbolicValue) resource).dependent, ResourceConstraint.class) == null; }
private List<ProgramState> addNullConstraintsForBooleanWrapper(ProgramState initialProgramState, List<ProgramState> copiedConstraints) { BooleanConstraint leftConstraint = initialProgramState.getConstraint(leftOp, BooleanConstraint.class); BooleanConstraint rightConstraint = initialProgramState.getConstraint(rightOp, BooleanConstraint.class); if (leftConstraint != null && rightConstraint == null && !isEquality()) { List<ProgramState> nullConstraints = copiedConstraints.stream() .flatMap(ps -> rightOp.setConstraint(ps, ObjectConstraint.NULL).stream()) .map(ps -> ps.removeConstraintsOnDomain(rightOp, BooleanConstraint.class) ).collect(Collectors.toList()); return ImmutableList.<ProgramState>builder().addAll(copiedConstraints).addAll(nullConstraints).build(); } return copiedConstraints; }
private List<ProgramState> addNullConstraintsForBooleanWrapper(ProgramState initialProgramState, List<ProgramState> copiedConstraints) { BooleanConstraint leftConstraint = initialProgramState.getConstraint(leftOp, BooleanConstraint.class); BooleanConstraint rightConstraint = initialProgramState.getConstraint(rightOp, BooleanConstraint.class); if (leftConstraint != null && rightConstraint == null && !isEquality()) { List<ProgramState> nullConstraints = copiedConstraints.stream() .flatMap(ps -> rightOp.setConstraint(ps, ObjectConstraint.NULL).stream()) .map(ps -> ps.removeConstraintsOnDomain(rightOp, BooleanConstraint.class) ).collect(Collectors.toList()); return ImmutableList.<ProgramState>builder().addAll(copiedConstraints).addAll(nullConstraints).build(); } return copiedConstraints; }
public List<ProgramState> setConstraint(ProgramState programState, BooleanConstraint booleanConstraint) { Constraint cstraint = programState.getConstraint(this, booleanConstraint.getClass()); if (!booleanConstraint.isValidWith(cstraint)) { return ImmutableList.of(); } return ImmutableList.of(programState.addConstraint(this, booleanConstraint)); }
public List<ProgramState> setConstraint(ProgramState programState, BooleanConstraint booleanConstraint) { Constraint cstraint = programState.getConstraint(this, booleanConstraint.getClass()); if (!booleanConstraint.isValidWith(cstraint)) { return ImmutableList.of(); } return ImmutableList.of(programState.addConstraint(this, booleanConstraint)); }
Set<LearnedConstraint> learnedConstraints(ProgramState parent) { ImmutableSet.Builder<LearnedConstraint> result = ImmutableSet.builder(); constraints.forEach((sv, pmap) -> pmap.forEach((domain, c) -> { if (!c.equals(parent.getConstraint(sv, domain))) { result.add(new LearnedConstraint(sv, c)); } })); return result.build(); }
protected void closeResource(@Nullable SymbolicValue target) { if (target != null) { CustomResourceConstraint oConstraint = programState.getConstraint(target, CustomResourceConstraint.class); if (oConstraint != null) { programState = programState.addConstraintTransitively(target.wrappedValue(), CLOSED); } } }
Set<LearnedConstraint> learnedConstraints(ProgramState parent) { ImmutableSet.Builder<LearnedConstraint> result = ImmutableSet.builder(); constraints.forEach((sv, pmap) -> pmap.forEach((domain, c) -> { if (!c.equals(parent.getConstraint(sv, domain))) { result.add(new LearnedConstraint(sv, c)); } })); return result.build(); }
protected void closeResource(@Nullable SymbolicValue target) { if (target != null) { CustomResourceConstraint oConstraint = programState.getConstraint(target, CustomResourceConstraint.class); if (oConstraint != null) { programState = programState.addConstraintTransitively(target.wrappedValue(), CLOSED); } } }
private void reuseSymbolicValue(SymbolicValue sv) { constraintManager.setValueFactory(() -> new DeferredConstraintHolderSV(programState.getConstraint(sv, ZeroConstraint.class)) { @Override public SymbolicValue wrappedValue() { return sv.wrappedValue(); } }); }
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 void reuseSymbolicValue(SymbolicValue sv) { constraintManager.setValueFactory(() -> new DeferredConstraintHolderSV(programState.getConstraint(sv, ZeroConstraint.class)) { @Override public SymbolicValue wrappedValue() { return sv.wrappedValue(); } }); }
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)); }
public List<ProgramState> setConstraint(ProgramState programState, Constraint constraint) { if(constraint instanceof BooleanConstraint) { return setConstraint(programState, (BooleanConstraint) constraint); } else if(constraint instanceof ObjectConstraint) { return setConstraint(programState, (ObjectConstraint) constraint); } Constraint csrtaint = programState.getConstraint(this, constraint.getClass()); if (constraint.isValidWith(csrtaint)) { return ImmutableList.of(programState.addConstraint(this, constraint)); } return ImmutableList.of(); }
private void closeResource(@Nullable final SymbolicValue target) { if (target instanceof ResourceWrapperSymbolicValue) { closeResource(target.wrappedValue()); } if (target != null) { ResourceConstraint oConstraint = programState.getConstraint(target, ResourceConstraint.class); if (oConstraint != null) { programState = programState.addConstraintTransitively(target, CLOSED); } } }
private void closeResource(@Nullable final SymbolicValue target) { if (target instanceof ResourceWrapperSymbolicValue) { closeResource(target.wrappedValue()); } if (target != null) { ResourceConstraint oConstraint = programState.getConstraint(target, ResourceConstraint.class); if (oConstraint != null) { programState = programState.addConstraintTransitively(target, CLOSED); } } }
private void checkReturnedValue(ReturnStatementTree tree, String nonNullAnnotation) { SymbolicValue returnedValue = programState.peekValue(); ObjectConstraint constraint = programState.getConstraint(returnedValue, ObjectConstraint.class); if (constraint != null && constraint.isNull()) { reportIssue(tree, "This method''s return value is marked \"{0}\" but null is returned.", nonNullAnnotation); } } }
private void checkReturnedValue(ReturnStatementTree tree, String nonNullAnnotation) { SymbolicValue returnedValue = programState.peekValue(); ObjectConstraint constraint = programState.getConstraint(returnedValue, ObjectConstraint.class); if (constraint != null && constraint.isNull()) { reportIssue(tree, "This method''s return value is marked \"{0}\" but null is returned.", nonNullAnnotation); } } }
private void checkNullArgument(Tree syntaxTree, JavaSymbol.MethodJavaSymbol symbol, JavaSymbol argumentSymbol, SymbolicValue argumentValue, int index) { ObjectConstraint constraint = programState.getConstraint(argumentValue, ObjectConstraint.class); if (constraint != null && constraint.isNull()) { String nonNullAnnotation = nonNullAnnotation(argumentSymbol); if (nonNullAnnotation != null) { String message = "Parameter {0} to this {1} is marked \"{2}\" but null could be passed."; reportIssue(syntaxTree, message, index + 1, (symbol.isConstructor() ? "constructor" : "call"), nonNullAnnotation); } } } }