[racerd] fix analysis of class initializers

Summary:
RacerD needs to analyse the class initialiser in order to establish field properties in its post, such as that certain static fields are synchronized containers.

There was a bug where class initializers were not analysed at all, from the time where there was no analysis of field properties in the post.

We still don't want to report on the class initialiser since it cannot possibly race with itself (JVM guarantees that) and it cannot race with any of the other methods in its class (because it must finish before any other method can be called).

Reviewed By: da319

Differential Revision: D26887151

fbshipit-source-id: 570aff370
master
Nikos Gorogiannis 4 years ago committed by Facebook GitHub Bot
parent b6c006f480
commit 6a19997303

@ -362,6 +362,7 @@ let should_report_on_proc tenv procdesc =
requested via @ThreadSafe in java *) requested via @ThreadSafe in java *)
RacerDModels.is_thread_safe_method proc_name tenv RacerDModels.is_thread_safe_method proc_name tenv
|| (not (PredSymb.equal_access (Procdesc.get_access procdesc) Private)) || (not (PredSymb.equal_access (Procdesc.get_access procdesc) Private))
&& (not (Procname.Java.is_class_initializer java_pname))
&& (not (Procname.Java.is_autogen_method java_pname)) && (not (Procname.Java.is_autogen_method java_pname))
&& not (Annotations.pdesc_return_annot_ends_with procdesc Annotations.visibleForTesting) && not (Annotations.pdesc_return_annot_ends_with procdesc Annotations.visibleForTesting)
| ObjC_Cpp objc_cpp when Procname.ObjC_Cpp.is_cpp_lambda objc_cpp -> | ObjC_Cpp objc_cpp when Procname.ObjC_Cpp.is_cpp_lambda objc_cpp ->

@ -343,8 +343,7 @@ let should_analyze_proc tenv pn =
(not (not
( match pn with ( match pn with
| Procname.Java java_pname -> | Procname.Java java_pname ->
Procname.Java.is_class_initializer java_pname Typ.Name.Java.is_external (Procname.Java.get_class_type_name java_pname)
|| Typ.Name.Java.is_external (Procname.Java.get_class_type_name java_pname)
(* third party code may be hard to change, not useful to report races there *) (* third party code may be hard to change, not useful to report races there *)
| _ -> | _ ->
false )) false ))

@ -386,4 +386,10 @@ class Containers {
byte[] raceOnMacDoFinalBad() { byte[] raceOnMacDoFinalBad() {
return mac.doFinal(); return mac.doFinal();
} }
static Set<Integer> staticSyncSet = new ConcurrentSkipListSet<Integer>();
static void staticAddToSyncIntegerSetOk(int s) {
staticSyncSet.add(s);
}
} }

Loading…
Cancel
Save