diff --git a/infer/src/checkers/eradicateChecks.ml b/infer/src/checkers/eradicateChecks.ml index 80eb2179c..7d4c7feaa 100644 --- a/infer/src/checkers/eradicateChecks.ml +++ b/infer/src/checkers/eradicateChecks.ml @@ -534,14 +534,17 @@ let check_overridden_annotations check_params overriden_proc_name overriden_signature | None -> () in - let check_overriden_methods super_class_name = + let check_overridden_methods super_class_name = let super_proc_name = Procname.java_replace_class proc_name super_class_name in let type_name = Sil.TN_csu (Sil.Class, Mangled.from_string super_class_name) in match Sil.tenv_lookup tenv type_name with | Some (Sil.Tstruct (_, _, _, _, _, methods, _)) -> + let is_override pname = + Procname.equal pname super_proc_name && + not (Procname.is_constructor pname) in list_iter (fun pname -> - if Procname.equal pname super_proc_name + if is_override pname then check pname) methods | _ -> () in @@ -555,4 +558,4 @@ let check_overridden_annotations list_map Mangled.to_string (PatternMatch.type_get_direct_supertypes curr_type) | None -> [] in - list_iter check_overriden_methods super_types + list_iter check_overridden_methods super_types diff --git a/infer/tests/codetoanalyze/java/eradicate/InconsistentSubclassAnnotation.java b/infer/tests/codetoanalyze/java/eradicate/InconsistentSubclassAnnotation.java index a4a798428..5578f7f1b 100644 --- a/infer/tests/codetoanalyze/java/eradicate/InconsistentSubclassAnnotation.java +++ b/infer/tests/codetoanalyze/java/eradicate/InconsistentSubclassAnnotation.java @@ -74,6 +74,19 @@ class SubclassExample { } } +class ConstructorsAreExcluded { + class Base { + Base (@Nullable String s) { + } + } + + class Derived extends Base { + Derived (String s) { // OK: there's no sub-typing between constructors + super(s); + } + } +} + public class InconsistentSubclassAnnotation { public static void callFromSuperclass(SubclassExample.A a) {