You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[pigeon]fix a crash when casting NSNull to an Array (#4289)
Fixes a crash introduced in #3658:
```
static func fromList(_ list: [Any?]) -> NativeAuthSession? {
if let userPoolTokensList = list[2] as! [Any?]? {}
}
```
where `list[2]` is `NSNull`, which is not an Optional, hence can't be casted to `[Any?]?`.
Recall that `nilOrValue` helper is created for this purpose. So the fix is simply:
```
static func fromList(_ list: [Any?]) -> NativeAuthSession? {
if let userPoolTokensList: [Any?] = nilOrValue(list[2]) {} // <- HERE
}
```
## Why didn't we catch this regression
Missing unit tests - we did not test `NSNull` fields to ensure `nilOrValue` works for them.
## Why did it work in previous version?
It's surprising that this worked fine before! The original code is:
```
static func fromList(_ list: [Any]) -> NativeAuthSession? {
if let userPoolTokensList = list[2] as! [Any]? {}
}
```
From [my previous PR](flutter/flutter#129283), we know that list[2] is an implicit optional (that contains a NSNull value). I think Swift made an exception here when casting implicit optional NSNull (either intentionally or unintentionally).
*List which issues are fixed by this PR. You must list at least one issue.*
Fixesflutter/flutter#129283
*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
Copy file name to clipboardExpand all lines: packages/pigeon/platform_tests/alternate_language_test_plugin/android/src/main/java/com/example/alternate_language_test_plugin/AlternateLanguageTestPlugin.java
0 commit comments