diff --git a/infer/src/IR/Typ.re b/infer/src/IR/Typ.re index a25b0e178..b4d476435 100644 --- a/infer/src/IR/Typ.re +++ b/infer/src/IR/Typ.re @@ -691,6 +691,10 @@ module Procname = { fun | Java j => String.is_prefix prefix::"lambda$" j.method_name | _ => false; + let java_is_generated = + fun + | Java j => String.is_prefix prefix::"$" j.method_name + | _ => false; /** Prints a string of a java procname with the given level of verbosity */ let java_to_string ::withclass=false (j: java) verbosity => diff --git a/infer/src/IR/Typ.rei b/infer/src/IR/Typ.rei index e2ef85082..9e8fac0ab 100644 --- a/infer/src/IR/Typ.rei +++ b/infer/src/IR/Typ.rei @@ -416,6 +416,9 @@ module Procname: { /** Check if the proc name comes from a lambda expression */ let java_is_lambda: t => bool; + /** Check if the proc name comes from generated code */ + let java_is_generated: t => bool; + /** Check if the last parameter is a hidden inner class, and remove it if present. This is used in private constructors, where a proxy constructor is generated with an extra parameter and calls the normal constructor. */ diff --git a/infer/src/backend/reporting.ml b/infer/src/backend/reporting.ml index 3b1667a18..d9da22be3 100644 --- a/infer/src/backend/reporting.ml +++ b/infer/src/backend/reporting.ml @@ -44,12 +44,16 @@ let log_issue_from_errlog err_kind err_log ?loc ?node_id ?session ?ltr ?linters_ let log_issue_from_summary err_kind summary ?loc ?node_id ?session ?ltr ?linters_def_file exn = + let is_generated_method = + Typ.Procname.java_is_generated (Specs.get_proc_name summary) in let should_suppress_lint = Config.curr_language_is Config.Java && Annotations.ia_is_suppress_lint (fst summary.Specs.attributes.ProcAttributes.method_annotation) in - if not should_suppress_lint + if should_suppress_lint || is_generated_method then + () (* Skip the reporting *) + else let err_log = summary.Specs.attributes.ProcAttributes.err_log in log_issue_from_errlog err_kind err_log ?loc ?node_id ?session ?ltr ?linters_def_file exn diff --git a/infer/tests/codetoanalyze/java/eradicate/ReturnNotNullable.java b/infer/tests/codetoanalyze/java/eradicate/ReturnNotNullable.java index fe8dc9e19..70f0f5791 100644 --- a/infer/tests/codetoanalyze/java/eradicate/ReturnNotNullable.java +++ b/infer/tests/codetoanalyze/java/eradicate/ReturnNotNullable.java @@ -152,4 +152,7 @@ public class ReturnNotNullable { return stream.map(x -> null); // Intentionaly not reporting here } + Object $generatedReturnsNullOk() { + return null; + } }