From fbeaf7731a18cbe26ef02b348ac60f35c4af778a Mon Sep 17 00:00:00 2001 From: Mitya Lyubarskiy Date: Thu, 26 Mar 2020 04:49:31 -0700 Subject: [PATCH] [nullsafe] Add known non-nullable alternatives for Android Fragment Summary: This is a fairly popular class that have bunch of nullable methods. Providing an alternative will make an error message actionable. Note that this involves some duplication, and the whole API could be improved. But let's leave it for future improvements. Reviewed By: jvillard Differential Revision: D20649099 fbshipit-source-id: bfcc7fd95 --- infer/src/nullsafe/modelTables.ml | 37 +++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/infer/src/nullsafe/modelTables.ml b/infer/src/nullsafe/modelTables.ml index 0b70108b2..780fca878 100644 --- a/infer/src/nullsafe/modelTables.ml +++ b/infer/src/nullsafe/modelTables.ml @@ -226,7 +226,7 @@ let mapPut_list = type nonnull_alternative_method = {package_name: string; class_name: string; method_name: string} -(* Nullable methods that have non-nullable signatures. +(* Nullable methods that have non-nullable alternatives. Format is a triple: (, , ), *) let nullable_methods_with_nonnull_alternatives_list = [ ( (n, [o]) @@ -238,7 +238,32 @@ let nullable_methods_with_nonnull_alternatives_list = , "android.app.Activity.findViewById(int):android.view.View" , { package_name= "androidx.core.app" ; class_name= "ActivityCompat" - ; method_name= "requireViewById" } ) ] + ; method_name= "requireViewById" } ) + ; ( (n, []) + , "androidx.fragment.app.Fragment.getArguments():android.os.Bundle" + , { package_name= "androidx.fragment.app" + ; class_name= "Fragment" + ; method_name= "requireArguments" } ) + ; ( (n, []) + , "androidx.fragment.app.Fragment.getContext():android.content.Context" + , {package_name= "androidx.fragment.app"; class_name= "Fragment"; method_name= "requireContext"} + ) + ; ( (n, []) + , "androidx.fragment.app.Fragment.getActivity():androidx.fragment.app.FragmentActivity" + , {package_name= "androidx.fragment.app"; class_name= "Fragment"; method_name= "requireActivity"} + ) + ; ( (n, []) + , "androidx.fragment.app.Fragment.getHost():java.lang.Object" + , {package_name= "androidx.fragment.app"; class_name= "Fragment"; method_name= "requireHost"} ) + ; ( (n, []) + , "androidx.fragment.app.Fragment.getParentFragment():androidx.fragment.app.Fragment" + , { package_name= "androidx.fragment.app" + ; class_name= "Fragment" + ; method_name= "requireParentFragment" } ) + ; ( (n, []) + , "androidx.fragment.app.Fragment.getView():android.view.View" + , {package_name= "androidx.fragment.app"; class_name= "Fragment"; method_name= "requireView"} ) + ] let nullable_method_with_nonnull_alternatives_nullability_list = @@ -265,6 +290,14 @@ let annotated_list_nullability_other = ; ( (o, [o; o]) , "androidx.core.app.ActivityCompat.requireViewById(android.app.Activity,int):android.view.View" ) + ; ((o, []), "androidx.fragment.app.Fragment.requireArguments():android.os.Bundle") + ; ((o, []), "androidx.fragment.app.Fragment.requireContext():android.content.Context") + ; ( (o, []) + , "androidx.fragment.app.Fragment.requireActivity():androidx.fragment.app.FragmentActivity" ) + ; ((o, []), "androidx.fragment.app.Fragment.requireHost():java.lang.Object") + ; ( (o, []) + , "androidx.fragment.app.Fragment.requireParentFragment():androidx.fragment.app.Fragment" ) + ; ((o, []), "androidx.fragment.app.Fragment.requireView():android.view.View") ; ( (o, [o; o; n; n; n]) , "com.android.sdklib.build.ApkBuilder.(java.io.File,java.io.File,java.io.File,java.lang.String,java.io.PrintStream)" )