use of org.sonar.java.se.constraint.ObjectConstraint in project sonar-java by SonarSource.
the class ParameterNullnessCheck method checkParameters.
private void checkParameters(Tree syntaxNode, Symbol symbol, Arguments arguments, ProgramState state) {
if (!symbol.isMethodSymbol() || arguments.isEmpty()) {
return;
}
JavaSymbol.MethodJavaSymbol methodSymbol = (JavaSymbol.MethodJavaSymbol) symbol;
if (nonNullAnnotationOnParameters(methodSymbol) == null) {
// method is not annotated (locally or globally)
return;
}
int nbArguments = arguments.size();
List<SymbolicValue> argumentSVs = getArgumentSVs(state, syntaxNode, nbArguments);
List<JavaSymbol> argumentSymbols = methodSymbol.getParameters().scopeSymbols();
int nbArgumentToCheck = Math.min(nbArguments, argumentSymbols.size() - (methodSymbol.isVarArgs() ? 1 : 0));
for (int i = 0; i < nbArgumentToCheck; i++) {
ObjectConstraint constraint = state.getConstraint(argumentSVs.get(i), ObjectConstraint.class);
if (constraint != null && constraint.isNull() && !parameterIsNullable(methodSymbol, argumentSymbols.get(i))) {
reportIssue(syntaxNode, arguments.get(i), methodSymbol);
}
}
}
Aggregations