Commit 905fa24
Fix KotlinNullableVariableCastToNonnullType in DefaultReactHost.kt (#55406)
Summary:
Pull Request resolved: #55406
Refactored getDefaultReactHost to prove that reactHost is never null at return time, eliminating the need for checkNotNull.
The original code used `checkNotNull(reactHost)` which was a runtime assertion. The refactored code uses a pattern that proves null-safety at compile time:
1. Early return with `?.let` if reactHost is already initialized
2. Create the new ReactHostImpl in a local `val newReactHost` (which compiler knows is non-null)
3. Assign to the class field and return the local variable directly
This approach eliminates the runtime check while maintaining the same singleton behavior.
changelog: [internal] internal
Reviewed By: javache
Differential Revision: D91820164
fbshipit-source-id: 4e550569e8473b549ba0debb701991a260a8dd041 parent 9bd72e7 commit 905fa24
1 file changed
Lines changed: 36 additions & 34 deletions
File tree
- packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults
Lines changed: 36 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
75 | 77 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
83 | 82 | | |
84 | | - | |
| 83 | + | |
85 | 84 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
111 | 113 | | |
112 | 114 | | |
113 | 115 | | |
| |||
0 commit comments