From 89a6d7e20d18d98544d75d59e3383b53e4a5cd7e Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Fri, 9 Mar 2018 14:57:07 -0800 Subject: [PATCH] [racerd] don't report races in third-party code Reviewed By: jeremydubreil Differential Revision: D7107581 fbshipit-source-id: 87cde65 --- infer/src/IR/Typ.ml | 8 +++++++ infer/src/IR/Typ.mli | 6 +++++ infer/src/checkers/NullabilitySuggest.ml | 4 +--- infer/src/concurrency/RacerDConfig.ml | 2 ++ .../codetoanalyze/java/racerd/.inferconfig | 3 +++ .../java/racerd/DoNotReport.java | 24 +++++++++++++++++++ 6 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 infer/tests/codetoanalyze/java/racerd/DoNotReport.java diff --git a/infer/src/IR/Typ.ml b/infer/src/IR/Typ.ml index 597a95235..8bae6c64a 100644 --- a/infer/src/IR/Typ.ml +++ b/infer/src/IR/Typ.ml @@ -435,6 +435,14 @@ module Name = struct is_int | None -> false + + + let is_external_classname name_string = + let package, _ = split_classname name_string in + Option.exists ~f:Config.java_package_is_external package + + + let is_external t = is_external_classname (name t) end module Cpp = struct diff --git a/infer/src/IR/Typ.mli b/infer/src/IR/Typ.mli index 0a63525a7..f922fdd7b 100644 --- a/infer/src/IR/Typ.mli +++ b/infer/src/IR/Typ.mli @@ -162,6 +162,12 @@ module Name : sig val is_class : t -> bool (** [is_class name] holds if [name] names a Java class *) + val is_external_classname : string -> bool + (** return true if the string is in the .inferconfig list of external classes *) + + val is_external : t -> bool + (** return true if the typename is in the .inferconfig list of external classes *) + val split_classname : string -> string option * string (** Given a package.class_name string, look for the latest dot and split the string in two (package, class_name). *) diff --git a/infer/src/checkers/NullabilitySuggest.ml b/infer/src/checkers/NullabilitySuggest.ml index 665a04f31..f01db8af1 100644 --- a/infer/src/checkers/NullabilitySuggest.ml +++ b/infer/src/checkers/NullabilitySuggest.ml @@ -155,9 +155,7 @@ let pretty_field_name proc_data field_name = let is_outside_codebase proc_name field_name = match proc_name with | Typ.Procname.Java _ -> - let class_name = Typ.Fieldname.Java.get_class field_name in - let package, _ = Typ.Name.Java.split_classname class_name in - Option.exists ~f:Config.java_package_is_external package + Typ.Name.Java.is_external_classname (Typ.Fieldname.Java.get_class field_name) | _ -> false diff --git a/infer/src/concurrency/RacerDConfig.ml b/infer/src/concurrency/RacerDConfig.ml index 486637496..bcb655341 100644 --- a/infer/src/concurrency/RacerDConfig.ml +++ b/infer/src/concurrency/RacerDConfig.ml @@ -481,6 +481,8 @@ module Models = struct ( match pn with | Typ.Procname.Java java_pname -> Typ.Procname.Java.is_class_initializer java_pname + || Typ.Name.Java.is_external (Typ.Procname.Java.get_class_type_name java_pname) + (* third party code may be hard to change, not useful to report races there *) | _ -> false ) && not (FbThreadSafety.is_logging_method pn) && not (pdesc_is_assumed_thread_safe pdesc tenv) diff --git a/infer/tests/codetoanalyze/java/racerd/.inferconfig b/infer/tests/codetoanalyze/java/racerd/.inferconfig index ad61ed582..ac67d2b48 100644 --- a/infer/tests/codetoanalyze/java/racerd/.inferconfig +++ b/infer/tests/codetoanalyze/java/racerd/.inferconfig @@ -6,5 +6,8 @@ "language": "Java", "source_contains": "_SHOULD_BE_SKIPPED_" } + ], + "external-java-packages" : [ + "com.racerd.donotreport" ] } diff --git a/infer/tests/codetoanalyze/java/racerd/DoNotReport.java b/infer/tests/codetoanalyze/java/racerd/DoNotReport.java new file mode 100644 index 000000000..bf96ced12 --- /dev/null +++ b/infer/tests/codetoanalyze/java/racerd/DoNotReport.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +package com.racerd.donotreport; + +import com.facebook.infer.annotation.ThreadSafe; + +@ThreadSafe +class DoNotReport { + + int mFld; + + // normally we would report this, but we won't because com.racerd.donotreport is blacklisted in + // .inferconfig + void obviousRaceBad(int i) { + mFld = i; + } +}