Skip to content

Commit

Permalink
[nullsafe] Add known non-nullable alternatives for Android Fragment
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mityal authored and facebook-github-bot committed Mar 26, 2020
1 parent 5df3801 commit fbeaf77
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions infer/src/nullsafe/modelTables.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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: (<nullability>, <method>, <alternative>), *)
let nullable_methods_with_nonnull_alternatives_list =
[ ( (n, [o])
Expand All @@ -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 =
Expand All @@ -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.<init>(java.io.File,java.io.File,java.io.File,java.lang.String,java.io.PrintStream)"
)
Expand Down

0 comments on commit fbeaf77

Please sign in to comment.