diff --git a/infer/src/checkers/ThreadSafety.ml b/infer/src/checkers/ThreadSafety.ml index 2567ce475..bd202f34e 100644 --- a/infer/src/checkers/ThreadSafety.ml +++ b/infer/src/checkers/ThreadSafety.ml @@ -1128,19 +1128,26 @@ let report_unsafe_accesses ~is_file_threadsafe aggregated_access_map = else match snd (TraceElem.kind access), pre with | Access.Write, AccessPrecondition.Unprotected _ -> - if threaded - then - reported_acc - else - begin - (* unprotected write. warn. *) - report_thread_safety_violation - tenv - pdesc - ~make_description:make_unprotected_write_description - access; - update_reported access pname reported_acc - end + begin + match Procdesc.get_proc_name pdesc with + | Java _ -> + if threaded + then + reported_acc + else + begin + (* unprotected write. warn. *) + report_thread_safety_violation + tenv + pdesc + ~make_description:make_unprotected_write_description + access; + update_reported access pname reported_acc + end + | _ -> + (* Do not report unprotected writes for ObjC_Cpp *) + reported_acc + end | Access.Write, AccessPrecondition.Protected _ -> (* protected write, do nothing *) reported_acc diff --git a/infer/tests/codetoanalyze/cpp/threadsafety/issues.exp b/infer/tests/codetoanalyze/cpp/threadsafety/issues.exp index 13fa8f951..82060295f 100644 --- a/infer/tests/codetoanalyze/cpp/threadsafety/issues.exp +++ b/infer/tests/codetoanalyze/cpp/threadsafety/issues.exp @@ -1,5 +1,3 @@ codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_get2, 3, THREAD_SAFETY_VIOLATION, [access to `suspiciously_written`] codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_get3, 0, THREAD_SAFETY_VIOLATION, [,access to `not_guarded`,,access to `not_guarded`] codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_get4, 0, THREAD_SAFETY_VIOLATION, [,access to `suspiciously_read`,,access to `suspiciously_read`] -codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_set, 1, THREAD_SAFETY_VIOLATION, [access to `not_guarded`] -codetoanalyze/cpp/threadsafety/basics.cpp, basics::Basic_set, 6, THREAD_SAFETY_VIOLATION, [access to `suspiciously_written`]