[infer][java] report nullable inconsistencies on library calls

Summary:
Report nullable inconsistencies by relying on the bytecode, and not on the presence of analysis summary on disk.

This use the `--external-java-packages` to avoid reporting inconsistencies outside of the codebase.

Reviewed By: sblackshear

Differential Revision: D7481101

fbshipit-source-id: 281135d
master
Jeremy Dubreil 7 years ago committed by Facebook Github Bot
parent 3784b7eca7
commit 5dea7c55e2

@ -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

@ -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

@ -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 *)

@ -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

@ -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.<init>(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.<init>(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.<init>(FieldNotInitialized), 0, ERADICATE_FIELD_NOT_INITIALIZED, ERROR, [Field `FieldNotInitialized$OnlyRead.o` is not initialized in the constructor and is not declared `@Nullable`]

Loading…
Cancel
Save