diff --git a/infer/src/IR/Typ.ml b/infer/src/IR/Typ.ml index 0b42c3fef..bbf467a43 100644 --- a/infer/src/IR/Typ.ml +++ b/infer/src/IR/Typ.ml @@ -708,6 +708,11 @@ module Procname = struct Note: currently only checks that the last argument has type Object[]. *) let is_vararg {parameters} = match List.last parameters with Some (_, "java.lang.Object[]") -> true | _ -> false + + + let is_external java_pname = + let package = get_package java_pname in + Option.exists ~f:Config.java_package_is_external package end module ObjC_Cpp = struct diff --git a/infer/src/IR/Typ.mli b/infer/src/IR/Typ.mli index b6ada6ba8..854ab4202 100644 --- a/infer/src/IR/Typ.mli +++ b/infer/src/IR/Typ.mli @@ -344,6 +344,9 @@ module Procname : sig val is_class_initializer : t -> bool (** Check if this is a class initializer. *) + + val is_external : t -> bool + (** Check if the method belongs to one of the specified external packages *) end module ObjC_Cpp : sig diff --git a/infer/src/eradicate/eradicateChecks.ml b/infer/src/eradicate/eradicateChecks.ml index 598455929..7590b9b5a 100644 --- a/infer/src/eradicate/eradicateChecks.ml +++ b/infer/src/eradicate/eradicateChecks.ml @@ -15,9 +15,6 @@ module L = Logging (* do not report RETURN_NOT_NULLABLE if the return is annotated @Nonnull *) let return_nonnull_silent = true -(* if true, check calls to libraries (i.e. not modelled and source not available) *) -let check_library_calls = false - let get_field_annotation tenv fn typ = let lookup = Tenv.lookup tenv in match Typ.Struct.get_field_type_and_annotation ~lookup fn typ with @@ -386,8 +383,8 @@ type resolved_param = ; propagates_nullable: bool } (** Check the parameters of a call. *) -let check_call_parameters tenv find_canonical_duplicate curr_pdesc node callee_summary_opt - callee_attributes resolved_params loc instr_ref : unit = +let check_call_parameters tenv find_canonical_duplicate curr_pdesc node callee_attributes + resolved_params loc instr_ref : unit = let callee_pname = callee_attributes.ProcAttributes.proc_name in let tot_param_num = List.length resolved_params in let check {num= param_num; formal= s1, ta1, t1; actual= orig_e2, ta2} = @@ -424,10 +421,11 @@ let check_call_parameters tenv find_canonical_duplicate curr_pdesc node callee_s if Config.eradicate_optional_present then check_ann AnnotatedSignature.Present ) in let should_check_parameters = - if check_library_calls then true - else - Models.is_modelled_nullable callee_pname || callee_attributes.ProcAttributes.is_defined - || Option.is_some callee_summary_opt + match callee_pname with + | Typ.Procname.Java java_pname -> + not (Typ.Procname.Java.is_external java_pname) || Models.is_modelled_nullable callee_pname + | _ -> + false in if should_check_parameters then (* left to right to avoid guessing the different lengths *) diff --git a/infer/src/eradicate/typeCheck.ml b/infer/src/eradicate/typeCheck.ml index a6df563f8..7f4223f37 100644 --- a/infer/src/eradicate/typeCheck.ml +++ b/infer/src/eradicate/typeCheck.ml @@ -831,7 +831,7 @@ let typecheck_instr tenv ext calls_this checks (node: Procdesc.Node.t) idenv get (typecheck_expr find_canonical_duplicate calls_this checks) ; if checks.eradicate then EradicateChecks.check_call_parameters tenv find_canonical_duplicate curr_pdesc node - callee_summary_opt callee_attributes resolved_params loc instr_ref ; + callee_attributes resolved_params loc instr_ref ; let typestate2 = if checks.check_extension then let etl' = List.map ~f:(fun ((_, e), t) -> (e, t)) call_params in diff --git a/infer/tests/codetoanalyze/java/eradicate/issues.exp b/infer/tests/codetoanalyze/java/eradicate/issues.exp index b41825f13..75795e39d 100644 --- a/infer/tests/codetoanalyze/java/eradicate/issues.exp +++ b/infer/tests/codetoanalyze/java/eradicate/issues.exp @@ -5,7 +5,9 @@ codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$Test codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestPropagatesNullable.mBad(), 1, ERADICATE_NULL_METHOD_CALL, ERROR, [origin,The value of `m(...)` in the call to `length()` could be null. (Origin: call to m(...) at line 83)] codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestTextUtilsIsEmpty.myTextUtilsIsEmpty(CharSequence), 2, ERADICATE_NULL_METHOD_CALL, ERROR, [The value of `s` in the call to `toString()` could be null. (Origin: method parameter s)] codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestTextUtilsIsEmpty.myTextUtilsNotIsNotEmpty(CharSequence), 2, ERADICATE_NULL_METHOD_CALL, ERROR, [The value of `s` in the call to `toString()` could be null. (Origin: method parameter s)] +codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestTextUtilsIsEmpty.textUtilsIsEmpty(CharSequence), 1, ERADICATE_PARAMETER_NOT_NULLABLE, ERROR, [`isEmpty(...)` needs a non-null value in parameter 1 but argument `s` can be null. (Origin: method parameter s)] codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestTextUtilsIsEmpty.textUtilsIsEmpty(CharSequence), 2, ERADICATE_NULL_METHOD_CALL, ERROR, [The value of `s` in the call to `toString()` could be null. (Origin: method parameter s)] +codetoanalyze/java/eradicate/CustomAnnotations.java, void CustomAnnotations$TestTextUtilsIsEmpty.textUtilsNotIsEmpty(CharSequence), 1, ERADICATE_PARAMETER_NOT_NULLABLE, ERROR, [`isEmpty(...)` needs a non-null value in parameter 1 but argument `s` can be null. (Origin: method parameter s)] codetoanalyze/java/eradicate/FieldNotInitialized.java, FieldNotInitialized$ConditionalFieldInit.(FieldNotInitialized), 0, ERADICATE_FIELD_NOT_INITIALIZED, ERROR, [Field `FieldNotInitialized$ConditionalFieldInit.o1` is not initialized in the constructor and is not declared `@Nullable`] codetoanalyze/java/eradicate/FieldNotInitialized.java, FieldNotInitialized$InitCircular.(FieldNotInitialized), 0, ERADICATE_FIELD_NOT_INITIALIZED, ERROR, [Field `FieldNotInitialized$InitCircular.s` is not initialized in the constructor and is not declared `@Nullable`] codetoanalyze/java/eradicate/FieldNotInitialized.java, FieldNotInitialized$OnlyRead.(FieldNotInitialized), 0, ERADICATE_FIELD_NOT_INITIALIZED, ERROR, [Field `FieldNotInitialized$OnlyRead.o` is not initialized in the constructor and is not declared `@Nullable`]