diff --git a/infer/src/java/jTrans.ml b/infer/src/java/jTrans.ml index 66d21fda4..1fc8543a9 100644 --- a/infer/src/java/jTrans.ml +++ b/infer/src/java/jTrans.ml @@ -646,7 +646,6 @@ let method_invocation (context : JContext.t) loc pc var_opt cn ms sil_obj_opt ex then proc else JTransType.get_method_procname program tenv cn' ms method_kind in - JClasspath.add_missing_callee program callee_procname cn' ms ; let call_instrs = let callee_fun = Exp.Const (Const.Cfun callee_procname) in let return_type = diff --git a/infer/src/java/jTransType.ml b/infer/src/java/jTransType.ml index 3387d1e54..852b5967a 100644 --- a/infer/src/java/jTransType.ml +++ b/infer/src/java/jTransType.ml @@ -308,7 +308,9 @@ let rec get_method_procname program tenv cn ms method_kind = (* create a mangled procname from an abstract or concrete method *) and translate_method_name program tenv m = let cn, ms = JBasics.cms_split (Javalib.get_class_method_signature m) in - get_method_procname program tenv cn ms (get_method_kind m) + let proc_name = get_method_procname program tenv cn ms (get_method_kind m) in + JClasspath.add_missing_callee program proc_name cn ms ; + proc_name and get_all_fields program tenv cn = diff --git a/infer/tests/build_systems/buck/issues.exp b/infer/tests/build_systems/buck/issues.exp index 779593bf1..a0e620126 100644 --- a/infer/tests/build_systems/buck/issues.exp +++ b/infer/tests/build_systems/buck/issues.exp @@ -1,5 +1,7 @@ infer/tests/build_systems/genrule/module1/Class1.java, genrule.module1.Class1.localNPE1():void, 2, ERADICATE_NULL_METHOD_CALL, no_bucket, WARNING, [origin,The value of `obj` in the call to `toString()` could be null. (Origin: null constant at line 24)] infer/tests/build_systems/genrule/module1/Class1.java, genrule.module1.Class1.unannotatedReturnNull():java.lang.Object, 0, ERADICATE_RETURN_NOT_NULLABLE, no_bucket, WARNING, [origin,Method `unannotatedReturnNull()` may return null but it is not annotated with `@Nullable`. (Origin: null constant at line 33)] +infer/tests/build_systems/genrule/module2/Class2.java, genrule.module2.Class2$Sub.subtypingInconsistency(java.lang.Object):java.lang.Object, 0, ERADICATE_INCONSISTENT_SUBCLASS_PARAMETER_ANNOTATION, no_bucket, WARNING, [First parameter `object` of method `Class2$Sub.subtypingInconsistency(...)` is not `@Nullable` but is declared `@Nullable`in the parent class method `Class1$Sub.subtypingInconsistency(...)`.] +infer/tests/build_systems/genrule/module2/Class2.java, genrule.module2.Class2$Sub.subtypingInconsistency(java.lang.Object):java.lang.Object, 0, ERADICATE_INCONSISTENT_SUBCLASS_RETURN_ANNOTATION, no_bucket, WARNING, [Method `Class2$Sub.subtypingInconsistency(...)` is annotated with `@Nullable` but overrides unannotated method `Class1$Sub.subtypingInconsistency(...)`.] infer/tests/build_systems/genrule/module2/Class2.java, genrule.module2.Class2.dereferenceInterTargetField1Bad(genrule.module1.Class1):void, 1, ERADICATE_NULL_METHOD_CALL, no_bucket, WARNING, [origin,The value of `class1.field1` in the call to `toString()` could be null. (Origin: field Class1.field1 at line 53)] infer/tests/build_systems/genrule/module2/Class2.java, genrule.module2.Class2.dereferenceInterTargetField2Bad(genrule.module1.Class1):int, 1, ERADICATE_NULL_FIELD_ACCESS, no_bucket, WARNING, [origin,Object `class1.field2` could be null when accessing field `Class1.x`. (Origin: field Class1.field2 at line 57)] infer/tests/build_systems/genrule/module2/Class2.java, genrule.module2.Class2.dereferenceLocalNullableFieldBad():void, 1, ERADICATE_NULL_METHOD_CALL, no_bucket, WARNING, [origin,The value of `Class2.field` in the call to `toString()` could be null. (Origin: field Class2.field at line 49)] diff --git a/infer/tests/build_systems/genrule/issues.exp b/infer/tests/build_systems/genrule/issues.exp index 480ad8410..003edfa71 100644 --- a/infer/tests/build_systems/genrule/issues.exp +++ b/infer/tests/build_systems/genrule/issues.exp @@ -1,3 +1,5 @@ +infer/tests/build_systems/genrule/module2/Class2.java, genrule.module2.Class2$Sub.subtypingInconsistency(java.lang.Object):java.lang.Object, 0, ERADICATE_INCONSISTENT_SUBCLASS_PARAMETER_ANNOTATION, no_bucket, WARNING, [First parameter `object` of method `Class2$Sub.subtypingInconsistency(...)` is not `@Nullable` but is declared `@Nullable`in the parent class method `Class1$Sub.subtypingInconsistency(...)`.] +infer/tests/build_systems/genrule/module2/Class2.java, genrule.module2.Class2$Sub.subtypingInconsistency(java.lang.Object):java.lang.Object, 0, ERADICATE_INCONSISTENT_SUBCLASS_RETURN_ANNOTATION, no_bucket, WARNING, [Method `Class2$Sub.subtypingInconsistency(...)` is annotated with `@Nullable` but overrides unannotated method `Class1$Sub.subtypingInconsistency(...)`.] infer/tests/build_systems/genrule/module2/Class2.java, genrule.module2.Class2.dereferenceInterTargetField1Bad(genrule.module1.Class1):void, 1, ERADICATE_NULL_METHOD_CALL, no_bucket, WARNING, [origin,The value of `class1.field1` in the call to `toString()` could be null. (Origin: field Class1.field1 at line 53)] infer/tests/build_systems/genrule/module2/Class2.java, genrule.module2.Class2.dereferenceInterTargetField2Bad(genrule.module1.Class1):int, 1, ERADICATE_NULL_FIELD_ACCESS, no_bucket, WARNING, [origin,Object `class1.field2` could be null when accessing field `Class1.x`. (Origin: field Class1.field2 at line 57)] infer/tests/build_systems/genrule/module2/Class2.java, genrule.module2.Class2.dereferenceLocalNullableFieldBad():void, 1, ERADICATE_NULL_METHOD_CALL, no_bucket, WARNING, [origin,The value of `Class2.field` in the call to `toString()` could be null. (Origin: field Class2.field at line 49)] diff --git a/infer/tests/build_systems/genrule/module1/Class1.java b/infer/tests/build_systems/genrule/module1/Class1.java index 6245cef47..08a6b63b4 100644 --- a/infer/tests/build_systems/genrule/module1/Class1.java +++ b/infer/tests/build_systems/genrule/module1/Class1.java @@ -32,4 +32,10 @@ public abstract class Class1 { public Object unannotatedReturnNull() { return null; } + + public static class Sub { + public Object subtypingInconsistency(@Nullable Object object) { + return new Object(); + } + } } diff --git a/infer/tests/build_systems/genrule/module2/Class2.java b/infer/tests/build_systems/genrule/module2/Class2.java index 4a6701175..a5b1dcfe1 100644 --- a/infer/tests/build_systems/genrule/module2/Class2.java +++ b/infer/tests/build_systems/genrule/module2/Class2.java @@ -60,4 +60,11 @@ public class Class2 { void dereferenceUnannotatedMethodReturningNullBad(Class1 class1) { class1.unannotatedReturnNull().toString(); } + + static class Sub extends Class1.Sub { + @Override + public @Nullable Object subtypingInconsistency(Object object) { + return null; + } + } }