private ProgramState checkConstraint(ProgramState programState, CheckerContext context, Tree syntaxNode, SymbolicValue currentVal) { ObjectConstraint constraint = programState.getConstraint(currentVal, ObjectConstraint.class); if (constraint != null && constraint.isNull()) { NullDereferenceIssue issue = new NullDereferenceIssue(context.getNode(), currentVal, syntaxNode); detectedIssues.peek().add(issue); // we reported the issue and stopped the exploration, but we still need to create a yield for x-procedural calls context.addExceptionalYield(currentVal, programState, JAVA_LANG_NPE, this); return null; } constraint = programState.getConstraint(currentVal, ObjectConstraint.class); if (constraint == null) { // a NPE will be triggered if the current value would have been null context.addExceptionalYield(currentVal, programState.addConstraint(currentVal, ObjectConstraint.NULL), JAVA_LANG_NPE, this); // We dereferenced the target value for the member select, so we can assume it is not null when not already known return programState.addConstraint(currentVal, ObjectConstraint.NOT_NULL); } return programState; }
private ProgramState checkConstraint(ProgramState programState, CheckerContext context, Tree syntaxNode, SymbolicValue currentVal) { ObjectConstraint constraint = programState.getConstraint(currentVal, ObjectConstraint.class); if (constraint != null && constraint.isNull()) { NullDereferenceIssue issue = new NullDereferenceIssue(context.getNode(), currentVal, syntaxNode); detectedIssues.peek().add(issue); // we reported the issue and stopped the exploration, but we still need to create a yield for x-procedural calls context.addExceptionalYield(currentVal, programState, JAVA_LANG_NPE, this); return null; } constraint = programState.getConstraint(currentVal, ObjectConstraint.class); if (constraint == null) { // a NPE will be triggered if the current value would have been null context.addExceptionalYield(currentVal, programState.addConstraint(currentVal, ObjectConstraint.NULL), JAVA_LANG_NPE, this); // We dereferenced the target value for the member select, so we can assume it is not null when not already known return programState.addConstraint(currentVal, ObjectConstraint.NOT_NULL); } return programState; }
private void handleDivide(Tree tree, SymbolicValue leftOp, SymbolicValue rightOp, Symbol rightOpSymbol) { if (isZero(rightOp)) { context.addExceptionalYield(rightOp, programState, "java.lang.ArithmeticException", DivisionByZeroCheck.this); reportIssue(tree, rightOp, rightOpSymbol); // interrupt exploration programState = null; } else if (isZero(leftOp)) { reuseSymbolicValue(leftOp); } else if (isNonZero(leftOp) && isNonZero(rightOp)) { // result of 'integer' can be zero or non-zero, depending of operands (for instance: '1 / 2 == 0') deferConstraint(null); } else if (hasNoConstraint(rightOp)) { ProgramState exceptionalState = programState .addConstraint(rightOp, ZeroConstraint.ZERO) // FIXME SONARJAVA-2125 - we should not have to add the NOT_NULL constraint for primitive types .addConstraint(rightOp, ObjectConstraint.NOT_NULL); context.addExceptionalYield(rightOp, exceptionalState, "java.lang.ArithmeticException", DivisionByZeroCheck.this); programState = programState.addConstraintTransitively(rightOp, ZeroConstraint.NON_ZERO); } }
private void handleDivide(Tree tree, SymbolicValue leftOp, SymbolicValue rightOp, Symbol rightOpSymbol) { if (isZero(rightOp)) { context.addExceptionalYield(rightOp, programState, "java.lang.ArithmeticException", DivisionByZeroCheck.this); reportIssue(tree, rightOp, rightOpSymbol); // interrupt exploration programState = null; } else if (isZero(leftOp)) { reuseSymbolicValue(leftOp); } else if (isNonZero(leftOp) && isNonZero(rightOp)) { // result of 'integer' can be zero or non-zero, depending of operands (for instance: '1 / 2 == 0') deferConstraint(null); } else if (hasNoConstraint(rightOp)) { ProgramState exceptionalState = programState .addConstraint(rightOp, ZeroConstraint.ZERO) // FIXME SONARJAVA-2125 - we should not have to add the NOT_NULL constraint for primitive types .addConstraint(rightOp, ObjectConstraint.NOT_NULL); context.addExceptionalYield(rightOp, exceptionalState, "java.lang.ArithmeticException", DivisionByZeroCheck.this); programState = programState.addConstraintTransitively(rightOp, ZeroConstraint.NON_ZERO); } }
constraintManager.setValueFactory(() -> new IsPresentSymbolicValue(peek)); } else if (OPTIONAL_GET.matches(tree) && presenceHasNotBeenChecked(peek)) { context.addExceptionalYield(peek, programState, "java.util.NoSuchElementException", check); reportIssue(tree);
constraintManager.setValueFactory(() -> new IsPresentSymbolicValue(peek)); } else if (OPTIONAL_GET.matches(tree) && presenceHasNotBeenChecked(peek)) { context.addExceptionalYield(peek, programState, "java.util.NoSuchElementException", check); reportIssue(tree);