From 8199ed1555fc7b0880e795db3885cfb41cf29a12 Mon Sep 17 00:00:00 2001 From: Mitya Lyubarskiy Date: Wed, 29 Jan 2020 03:08:25 -0800 Subject: [PATCH] [nullsafe] Add `nullsafe_FIXME` method to suppress nullability issues. Summary: This will help adoption of non-transitive strictification modes. The main use-case we are aiming with this function is: - During strictification, a method is made nullable, but it is not feasible to fix all callers straight away. Suppressing nullsafe with an appropriate task or comment will make it easier to unblock the strictification and move forward. Reviewed By: artempyanykh Differential Revision: D19599098 fbshipit-source-id: 3769bbd3d --- .../java/com/facebook/infer/annotation/Assertions.java | 9 +++++++++ infer/src/nullsafe/modelTables.ml | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/infer/annotations/src/main/java/com/facebook/infer/annotation/Assertions.java b/infer/annotations/src/main/java/com/facebook/infer/annotation/Assertions.java index faf4ac728..764c21bab 100644 --- a/infer/annotations/src/main/java/com/facebook/infer/annotation/Assertions.java +++ b/infer/annotations/src/main/java/com/facebook/infer/annotation/Assertions.java @@ -54,6 +54,15 @@ public class Assertions { return object; } + /** + * Makes Nullsafe stop complaining when {@code object} is dereferenced or converted to a + * non-nullable. In contrast with {@link #assumeNotNull()}, indicates cases when the proper fix + * needs to be committed, but for some reason it is hard or impossible to do it staight away. + */ + public static T nullsafeFIXME(@Nullable T object, String explanationOrTask) { + return object; + } + public static T assertGet(int index, List list) { assertCondition(0 <= index && index < list.size(), "Index not in bound"); return assertNotNull(list.get(index), "Null value"); diff --git a/infer/src/nullsafe/modelTables.ml b/infer/src/nullsafe/modelTables.ml index 44b916b0f..e0620eff7 100644 --- a/infer/src/nullsafe/modelTables.ml +++ b/infer/src/nullsafe/modelTables.ml @@ -140,6 +140,10 @@ let check_not_null_parameter_list, check_not_null_list = , (o, [n; o]) , "com.facebook.infer.annotation.Assertions.assumeNotNull(java.lang.Object,java.lang.String):java.lang.Object" ) + ; ( 1 + , (o, [n; o]) + , "com.facebook.infer.annotation.Assertions.nullsafeFIXME(java.lang.Object,java.lang.String):java.lang.Object" + ) ; ( 1 , (o, [n]) , "androidx.core.util.Preconditions.checkNotNull(java.lang.Object):java.lang.Object" )