don't warn if procedure is marked VisibleForTesting

Reviewed By: jvillard

Differential Revision: D3467885

fbshipit-source-id: 80f5f6b
master
Sam Blackshear 9 years ago committed by Facebook Github Bot 2
parent 03df3a0c47
commit 9d95a3a199

@ -741,6 +741,7 @@ let add_guarded_by_constraints prop lexp pdesc =
(Prop.get_exp_attributes prop guarded_by_exp) in (Prop.get_exp_attributes prop guarded_by_exp) in
let should_warn pdesc = let should_warn pdesc =
Cfg.Procdesc.get_access pdesc <> Sil.Private && Cfg.Procdesc.get_access pdesc <> Sil.Private &&
not (Annotations.pdesc_has_annot pdesc Annotations.visibleForTesting) &&
not (Procname.java_is_access_method (Cfg.Procdesc.get_proc_name pdesc)) in not (Procname.java_is_access_method (Cfg.Procdesc.get_proc_name pdesc)) in
match find_guarded_by_exp guarded_by_str (Prop.get_sigma prop) with match find_guarded_by_exp guarded_by_str (Prop.get_sigma prop) with
| Some (Sil.Eexp (guarded_by_exp, _), typ) -> | Some (Sil.Eexp (guarded_by_exp, _), typ) ->

@ -108,6 +108,9 @@ let ma_contains ma ann_names =
) ma; ) ma;
!found !found
let pdesc_has_annot pdesc annot =
ma_contains (Cfg.Procdesc.get_attributes pdesc).ProcAttributes.method_annotation [annot]
let initializer_ = "Initializer" let initializer_ = "Initializer"
let inject = "Inject" let inject = "Inject"
let inject_view = "InjectView" let inject_view = "InjectView"

@ -103,11 +103,9 @@ val ia_is_guarded_by : Typ.item_annotation -> bool
val ia_iter : (Typ.annotation -> unit) -> Typ.item_annotation -> unit val ia_iter : (Typ.annotation -> unit) -> Typ.item_annotation -> unit
val ma_contains : Typ.method_annotation -> string list -> bool
val ma_has_annotation_with : Typ.method_annotation -> (Typ.annotation -> bool) -> bool val ma_has_annotation_with : Typ.method_annotation -> (Typ.annotation -> bool) -> bool
val ma_iter : (Typ.annotation -> unit) -> Typ.method_annotation -> unit val pdesc_has_annot : Cfg.Procdesc.t -> string -> bool
(** Mark the return of the method_annotation with the given annotation. *) (** Mark the return of the method_annotation with the given annotation. *)
val method_annotation_mark_return : val method_annotation_mark_return :

@ -396,8 +396,7 @@ let callback_test_state { Callbacks.proc_name } =
(** Check the uses of VisibleForTesting *) (** Check the uses of VisibleForTesting *)
let callback_checkVisibleForTesting { Callbacks.proc_desc } = let callback_checkVisibleForTesting { Callbacks.proc_desc } =
let ma = (Specs.pdesc_resolve_attributes proc_desc).ProcAttributes.method_annotation in if Annotations.pdesc_has_annot proc_desc Annotations.visibleForTesting then
if Annotations.ma_contains ma [Annotations.visibleForTesting] then
begin begin
let loc = Cfg.Procdesc.get_loc proc_desc in let loc = Cfg.Procdesc.get_loc proc_desc in
let linereader = Printer.LineReader.create () in let linereader = Printer.LineReader.create () in

@ -13,6 +13,8 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import com.google.common.annotations.VisibleForTesting;
import java.io.Closeable; import java.io.Closeable;
public class GuardedByExample { public class GuardedByExample {
@ -251,6 +253,16 @@ public class GuardedByExample {
}; };
} }
@VisibleForTesting
public void visibleForTestingOk1() {
f.toString(); // should push proof obl to caller
}
@VisibleForTesting
void visibleForTestingOk2() {
f.toString(); // should push proof obl to caller
}
// TODO: report on these cases // TODO: report on these cases
/* /*
public void unguardedCallSiteBad1() { public void unguardedCallSiteBad1() {

Loading…
Cancel
Save