diff --git a/infer/src/absint/PatternMatch.ml b/infer/src/absint/PatternMatch.ml index 180830a5c..ab919cef6 100644 --- a/infer/src/absint/PatternMatch.ml +++ b/infer/src/absint/PatternMatch.ml @@ -109,9 +109,11 @@ module Java = struct supertype_exists tenv is_interface (Typ.Name.Java.from_string typename) + let implements_lang class_name = implements ("java.lang." ^ class_name) + let implements_arrays = implements "java.util.Arrays" - let implements_iterable = implements "java.lang.Iterable" + let implements_iterable = implements_lang "Iterable" let implements_iterator = implements "java.util.Iterator" @@ -121,7 +123,11 @@ module Java = struct let implements_list = implements "java.util.List" - let implements_math = implements "java.lang.Math" + let implements_math = implements_lang "Math" + + let implements_number = implements_lang "Number" + + let implements_system = implements_lang "System" let implements_xmob_utils class_name = implements ("com.moblica.common.xmob.utils." ^ class_name) @@ -162,8 +168,6 @@ module Java = struct let implements_queue = implements "java.util.Queue" - let implements_lang class_name = implements ("java.lang." ^ class_name) - let implements_google class_name = implements ("com.google." ^ class_name) let implements_android class_name = implements ("android." ^ class_name) diff --git a/infer/src/absint/PatternMatch.mli b/infer/src/absint/PatternMatch.mli index 7ef3b7e04..3c60f25e9 100644 --- a/infer/src/absint/PatternMatch.mli +++ b/infer/src/absint/PatternMatch.mli @@ -95,6 +95,9 @@ module Java : sig val implements_nio : string -> Tenv.t -> string -> bool (** Check whether class implements a Java nio *) + val implements_number : Tenv.t -> string -> bool + (** Check whether class implements a Java's Number *) + val implements_org_json : string -> Tenv.t -> string -> bool (** Check whether class implements a class from Json *) @@ -113,6 +116,9 @@ module Java : sig val implements_sparse_float_array : Tenv.t -> string -> bool (** Check whether class implements a class of [com.facebook.litho.internal.SparseFloatArray] *) + val implements_system : Tenv.t -> string -> bool + (** Check whether class implements a Java's System *) + val implements_view_group : Tenv.t -> string -> bool (** Check whether class implements a class of [android.view.ViewGroup] *) diff --git a/infer/src/checkers/ConfigImpactAnalysis.ml b/infer/src/checkers/ConfigImpactAnalysis.ml index dbffa3ae6..75c9e27a5 100644 --- a/infer/src/checkers/ConfigImpactAnalysis.ml +++ b/infer/src/checkers/ConfigImpactAnalysis.ml @@ -375,10 +375,40 @@ module TransferFunctions = struct && Procname.get_method pname |> String.equal "booleanValue" + let is_cheap_system_method = + let cheap_system_methods = + String.Set.of_list + [ "clearProperty" + ; "console" + ; "currentTimeMillis" + ; "exit" + ; "getEnv" + ; "getLogger" + ; "getProperties" + ; "getProperty" + ; "getSecurityManager" + ; "identityHashCode​" + ; "inheritedChannel" + ; "lineSeparator" + ; "mapLibraryName​" + ; "nanoTime" + ; "setErr" + ; "setIn" + ; "setOut" + ; "setProperties" + ; "setProperty" + ; "setSecurityManager" ] + in + fun _ method_name -> String.Set.mem cheap_system_methods method_name + + let is_known_cheap_method = let dispatch : (Tenv.t, unit, unit) ProcnameDispatcher.ProcName.dispatcher = let open ProcnameDispatcher.ProcName in - make_dispatcher [+PatternMatch.Java.implements_math &::.*--> ()] + make_dispatcher + [ +PatternMatch.Java.implements_math &::.*--> () + ; +PatternMatch.Java.implements_number &::.*--> () + ; +PatternMatch.Java.implements_system &::+ is_cheap_system_method &--> () ] in fun tenv pname -> dispatch tenv pname |> Option.is_some