diff --git a/infer/src/checkers/annotations.ml b/infer/src/checkers/annotations.ml index a9385c518..8a758b7ca 100644 --- a/infer/src/checkers/annotations.ml +++ b/infer/src/checkers/annotations.ml @@ -48,13 +48,11 @@ let ia_has_annotation_with ia; !found -(** Return true if [annot] ends with [ann_name] *) +(** Return true if [annot] ends with [ann_name], ignoring the package name *) let annot_ends_with annot ann_name = - let filter s = - let sl = String.length s in - let al = String.length ann_name in - sl >= al && String.sub s ~pos:(sl - al) ~len:al = ann_name in - filter annot.Annot.class_name + match String.rsplit2 annot.Annot.class_name ~on:'.' with + | None -> String.equal annot.Annot.class_name ann_name + | Some (_, annot_class_name) -> String.equal annot_class_name ann_name (** Check if there is an annotation in [ia] which ends with the given name *) let ia_ends_with ia ann_name = diff --git a/infer/tests/codetoanalyze/java/eradicate/DefinitelyNotNullable.java b/infer/tests/codetoanalyze/java/eradicate/DefinitelyNotNullable.java new file mode 100644 index 000000000..9b2e273da --- /dev/null +++ b/infer/tests/codetoanalyze/java/eradicate/DefinitelyNotNullable.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2013 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +package codetoanalyze.java.eradicate; + +@interface DefinitelyNotNullable {} diff --git a/infer/tests/codetoanalyze/java/eradicate/ReturnNotNullable.java b/infer/tests/codetoanalyze/java/eradicate/ReturnNotNullable.java index 7cab668ee..5830cb448 100644 --- a/infer/tests/codetoanalyze/java/eradicate/ReturnNotNullable.java +++ b/infer/tests/codetoanalyze/java/eradicate/ReturnNotNullable.java @@ -127,4 +127,13 @@ public class ReturnNotNullable { return cls.getResource(name); } + @DefinitelyNotNullable + Object definitelyDoesNotReturnNull() { + return new Object(); + } + + void callsnotnullableMethod() { + definitelyDoesNotReturnNull().toString(); + } + }