private static boolean isUndefinedOrNull(CheckerContext context, Symbol symbol) { ProgramState programState = context.getState(); SymbolicValue value = programState.getValue(symbol); return value == null; }
private static boolean isUndefinedOrNull(CheckerContext context, Symbol symbol) { ProgramState programState = context.getState(); SymbolicValue value = programState.getValue(symbol); return value == null; }
Set<LearnedAssociation> learnedAssociations(ProgramState parent) { ImmutableSet.Builder<LearnedAssociation> result = ImmutableSet.builder(); values.forEach((s, sv) -> { if (parent.getValue(s) != sv) { result.add(new LearnedAssociation(sv, s)); } }); return result.build(); } }
Set<LearnedAssociation> learnedAssociations(ProgramState parent) { ImmutableSet.Builder<LearnedAssociation> result = ImmutableSet.builder(); values.forEach((s, sv) -> { if (parent.getValue(s) != sv) { result.add(new LearnedAssociation(sv, s)); } }); return result.build(); } }
private void visitMethodInvocationWithIdentifierTarget(final String methodName, final IdentifierTree target) { if (!isMemberSelectActingOnField(target)) { final SymbolicValue symbolicValue = programState.getValue(target.symbol()); if (LOCK_METHOD_NAME.equals(methodName) || TRY_LOCK_METHOD_NAME.equals(methodName)) { programState = programState.addConstraintTransitively(symbolicValue, LockConstraint.LOCKED); } else if (UNLOCK_METHOD_NAME.equals(methodName)) { programState = programState.addConstraintTransitively(symbolicValue, LockConstraint.UNLOCKED); } } } }
private void visitMethodInvocationWithIdentifierTarget(final String methodName, final IdentifierTree target) { if (!isMemberSelectActingOnField(target)) { final SymbolicValue symbolicValue = programState.getValue(target.symbol()); if (LOCK_METHOD_NAME.equals(methodName) || TRY_LOCK_METHOD_NAME.equals(methodName)) { programState = programState.addConstraintTransitively(symbolicValue, LockConstraint.LOCKED); } else if (UNLOCK_METHOD_NAME.equals(methodName)) { programState = programState.addConstraintTransitively(symbolicValue, LockConstraint.UNLOCKED); } } } }
@Override public void visitIdentifier(IdentifierTree tree) { // close resource as soon as it is encountered in the resource declaration if (isTryStatementResource(tree)) { Symbol symbol = tree.symbol(); closeResource(programState.getValue(symbol)); } } }
@Override public void visitIdentifier(IdentifierTree tree) { // close resource as soon as it is encountered in the resource declaration if (isTryStatementResource(tree)) { Symbol symbol = tree.symbol(); closeResource(programState.getValue(symbol)); } } }
private Optional<JavaFileScannerContext.Location> flowFromCaughtException(ExplodedGraph.Edge edge) { ProgramPoint programPoint = edge.parent.programPoint; if (((CFG.Block) programPoint.block).isCatchBlock() && programPoint.i == 0) { VariableTree catchVariable = ((VariableTree) programPoint.syntaxTree()); SymbolicValue.CaughtExceptionSymbolicValue caughtSv = ((SymbolicValue.CaughtExceptionSymbolicValue) edge.child.programState.getValue(catchVariable.symbol())); Preconditions.checkNotNull(caughtSv, "Caught exception not found in program state"); Type exceptionType = caughtSv.exception().exceptionType(); return Optional.of(location(edge.parent, String.format("%s is caught.", exceptionName(exceptionType)))); } return Optional.empty(); }
private Optional<JavaFileScannerContext.Location> flowFromCaughtException(ExplodedGraph.Edge edge) { ProgramPoint programPoint = edge.parent.programPoint; if (((CFG.Block) programPoint.block).isCatchBlock() && programPoint.i == 0) { VariableTree catchVariable = ((VariableTree) programPoint.syntaxTree()); SymbolicValue.CaughtExceptionSymbolicValue caughtSv = ((SymbolicValue.CaughtExceptionSymbolicValue) edge.child.programState.getValue(catchVariable.symbol())); Preconditions.checkNotNull(caughtSv, "Caught exception not found in program state"); Type exceptionType = caughtSv.exception().exceptionType(); return Optional.of(location(edge.parent, String.format("%s is caught.", exceptionName(exceptionType)))); } return Optional.empty(); }
private void executeIdentifier(IdentifierTree tree) { Symbol symbol = tree.symbol(); SymbolicValue value = programState.getValue(symbol); if (value == null) { value = constraintManager.createSymbolicValue(tree); programState = programState.put(symbol, value); } programState = programState.stackValue(value); }
private SymbolicValue getTargetValue(MethodInvocationTree syntaxNode) { ExpressionTree targetExpression = ((MemberSelectExpressionTree) syntaxNode.methodSelect()).expression(); SymbolicValue value; if (targetExpression.is(Tree.Kind.IDENTIFIER)) { IdentifierTree identifier = (IdentifierTree) targetExpression; value = programState.getValue(identifier.symbol()); } else { value = programState.peekValue(); } return value; }
private SymbolicValue getTargetValue(MethodInvocationTree syntaxNode) { ExpressionTree targetExpression = ((MemberSelectExpressionTree) syntaxNode.methodSelect()).expression(); SymbolicValue value; if (targetExpression.is(Tree.Kind.IDENTIFIER)) { IdentifierTree identifier = (IdentifierTree) targetExpression; value = programState.getValue(identifier.symbol()); } else { value = programState.peekValue(); } return value; }
private void visitMethodInvocationWithIdentifierTarget(final String methodName, final IdentifierTree target) { if (!isMemberSelectActingOnField(target)) { final SymbolicValue symbolicValue = programState.getValue(target.symbol()); if (LOCK_METHOD_NAME.equals(methodName)) { programState = programState.addConstraint(symbolicValue, new ObjectConstraint(false, false, target, Status.LOCKED)); } else if (TRY_LOCK_METHOD_NAME.equals(methodName)) { constraintManager.setValueFactory(new TryLockSymbolicValueFactory(symbolicValue)); programState = programState.addConstraint(symbolicValue, new ObjectConstraint(false, false, target, Status.LOCKED)); } else if (UNLOCK_METHOD_NAME.equals(methodName)) { programState = programState.addConstraint(symbolicValue, new ObjectConstraint(target, Status.UNLOCKED)); } } }
private SymbolicValue getTargetValue(MethodInvocationTree syntaxNode) { final ExpressionTree targetExpression = ((MemberSelectExpressionTree) syntaxNode.methodSelect()).expression(); final SymbolicValue value; if (targetExpression.is(Tree.Kind.IDENTIFIER)) { final IdentifierTree identifier = (IdentifierTree) targetExpression; value = programState.getValue(identifier.symbol()); } else { value = programState.peekValue(); } return value; }
private void executeIdentifier(IdentifierTree tree) { Symbol symbol = tree.symbol(); SymbolicValue value = programState.getValue(symbol); if (value == null) { value = constraintManager.createSymbolicValue(tree); programState = programState.stackValue(value, symbol); learnIdentifierConstraints(tree, value); } else { programState = programState.stackValue(value, symbol); } programState = programState.put(symbol, value); }
private void executeIdentifier(IdentifierTree tree) { Symbol symbol = tree.symbol(); SymbolicValue value = programState.getValue(symbol); if (value == null) { value = constraintManager.createSymbolicValue(tree); programState = programState.stackValue(value, symbol); learnIdentifierConstraints(tree, value); } else { programState = programState.stackValue(value, symbol); } programState = programState.put(symbol, value); }
@Override public void visitReturnStatement(ReturnStatementTree syntaxNode) { SymbolicValue currentVal = programState.peekValue(); if (currentVal != null) { final ExpressionTree expression = syntaxNode.expression(); if (expression != null) { if (expression.is(Tree.Kind.IDENTIFIER)) { final IdentifierTree identifier = (IdentifierTree) expression; currentVal = programState.getValue(identifier.symbol()); } else { currentVal = programState.peekValue(); } closeResource(currentVal); } } }
@Override public void visitMethodInvocation(MethodInvocationTree syntaxNode) { if (syntaxNode.methodSelect().is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree memberSelect = (MemberSelectExpressionTree) syntaxNode.methodSelect(); final ExpressionTree expression = memberSelect.expression(); if (expression.is(Tree.Kind.IDENTIFIER) && expression.symbolType().isSubtypeOf(LOCK)) { final String methodName = memberSelect.identifier().name(); IdentifierTree target = (IdentifierTree) expression; if (!isMemberSelectActingOnField(target) && TRY_LOCK_METHOD_NAME.equals(methodName)) { final SymbolicValue symbolicValue = programState.getValue(target.symbol()); constraintManager.setValueFactory(new TryLockSymbolicValueFactory(symbolicValue)); } } } }
@Override public void visitMethodInvocation(MethodInvocationTree syntaxNode) { if (syntaxNode.methodSelect().is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree memberSelect = (MemberSelectExpressionTree) syntaxNode.methodSelect(); final ExpressionTree expression = memberSelect.expression(); if (expression.is(Tree.Kind.IDENTIFIER) && expression.symbolType().isSubtypeOf(LOCK)) { final String methodName = memberSelect.identifier().name(); IdentifierTree target = (IdentifierTree) expression; if (!isMemberSelectActingOnField(target) && TRY_LOCK_METHOD_NAME.equals(methodName)) { final SymbolicValue symbolicValue = programState.getValue(target.symbol()); constraintManager.setValueFactory(new TryLockSymbolicValueFactory(symbolicValue)); } } } }