From ea8f9c9e9179e16ca2dbd4855568d5d6f5dea0ce Mon Sep 17 00:00:00 2001 From: Artem Pianykh Date: Mon, 3 Aug 2020 08:04:46 -0700 Subject: [PATCH] [java][frontend] Skip concrete method capture in Kotlin classes Summary: Capture of certain Kotlin files fails at the javalib level (probably, some unanticipated bytecode pattern). We however can't just completely skip Kotlin class-files during capture as those have NotNull/Nullable annotations on methods/params that are important for Java <- Kotlin interop (using Kt classes from Java). Instead we can skip translation of concrete methods from Kotlin classes while retaining method signatures with annots in the TEnv. Reviewed By: ngorogiannis Differential Revision: D22897638 fbshipit-source-id: 67909aa43 --- infer/src/base/Config.ml | 2 ++ infer/src/base/Config.mli | 2 ++ infer/src/base/SourceFile.ml | 2 ++ infer/src/base/SourceFile.mli | 3 +++ infer/src/java/jFrontend.ml | 6 ++++-- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 254bd9232..c410de766 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -186,6 +186,8 @@ let smt_output = false let source_file_extentions = [".java"; ".m"; ".mm"; ".c"; ".cc"; ".cpp"; ".h"] +let kotlin_source_extension = ".kt" + let specs_files_suffix = ".specs" (** Enable detailed tracing information during array abstraction *) diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index fca3c90f9..4b9bc8141 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -126,6 +126,8 @@ val smt_output : bool val source_file_extentions : string list +val kotlin_source_extension : string + val sourcepath : string option val sources : string list diff --git a/infer/src/base/SourceFile.ml b/infer/src/base/SourceFile.ml index de0c4d8f3..25bb39162 100644 --- a/infer/src/base/SourceFile.ml +++ b/infer/src/base/SourceFile.ml @@ -73,6 +73,8 @@ let to_string = else path +let has_extension t ~ext = String.is_suffix (to_string t) ~suffix:ext + let pp fmt fname = Format.pp_print_string fmt (to_string fname) let to_abs_path fname = diff --git a/infer/src/base/SourceFile.mli b/infer/src/base/SourceFile.mli index 1c174b1a2..51d6d544e 100644 --- a/infer/src/base/SourceFile.mli +++ b/infer/src/base/SourceFile.mli @@ -62,4 +62,7 @@ val to_string : ?force_relative:bool -> t -> string (** convert a source file to a string WARNING: result may not be valid file path, do not use this function to perform operations on filenames *) +val has_extension : t -> ext:string -> bool +(** returns whether the source file has provided extension *) + module SQLite : SqliteUtils.Data with type t = t diff --git a/infer/src/java/jFrontend.ml b/infer/src/java/jFrontend.ml index 7dd9500fa..a07613fee 100644 --- a/infer/src/java/jFrontend.ml +++ b/infer/src/java/jFrontend.ml @@ -89,8 +89,10 @@ let add_edges (context : JContext.t) start_node exn_node exit_nodes method_body_ (** Add a concrete method. *) let add_cmethod source_file program icfg cm proc_name = let cn, _ = JBasics.cms_split cm.Javalib.cm_class_method_signature in - if Inferconfig.skip_implementation_matcher source_file proc_name then - ignore (JTrans.create_empty_procdesc source_file program icfg cm proc_name) + if + Inferconfig.skip_implementation_matcher source_file proc_name + || SourceFile.has_extension source_file ~ext:Config.kotlin_source_extension + then ignore (JTrans.create_empty_procdesc source_file program icfg cm proc_name) else match JTrans.create_cm_procdesc source_file program icfg cm proc_name with | None ->