-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
flutter/packages
#3545Closed
Copy link
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: fatal crashCrashes that terminate the processCrashes that terminate the processe: OS-version specificAffects only some versions of the relevant operating systemAffects only some versions of the relevant operating systemfound in release: 3.7Found to occur in 3.7Found to occur in 3.7found in release: 3.9Found to occur in 3.9Found to occur in 3.9has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: pigeonrelated to pigeon messaging codegen toolrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-iosiOS applications specificallyiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Description
Use case
My Pigeon template definition is as follows:
class RequestParam {
late String key;
Map<String?, Object?>? data;
}
class ResponseParam {
late ResponseCode code;
String? message;
Map<String?, Object?>? data;
}Here's an example of a generated Swift code block:
/// Generated class from Pigeon that represents data sent in messages.
struct RequestParam {
var key: String
var data: [String?: Any?]? = nil
static func fromList(_ list: [Any]) -> RequestParam? {
let key = list[0] as! String
let data = list[1] as! [String?: Any?]?
return RequestParam(
key: key,
data: data
)
}
func toList() -> [Any?] {
return [
key,
data,
]
}
}
/// Generated class from Pigeon that represents data sent in messages.
struct ResponseParam {
var code: ResponseCode
var message: String? = nil
var data: [String?: Any?]? = nil
static func fromList(_ list: [Any]) -> ResponseParam? {
let code = ResponseCode(rawValue: list[0] as! Int)!
let message = list[1] as! String?
let data = list[2] as! [String?: Any?]?
return ResponseParam(
code: code,
message: message,
data: data
)
}
func toList() -> [Any?] {
return [
code.rawValue,
message,
data,
]
}
}When I use it like this, it crashes
func disconnect(param: RequestParam) throws -> ResponseParam {
pushBridge?.disConnect()
return ResponseParam(code: .success)
}I see. The reason for the crash could be that both data and message have been converted to NSNull

Proposal
Changing the code from:
let message = list[1] as! String?
let data = list[2] as! [String?: Any?]? to
let message = list[1] as? String
let data = list[2] as? [String?: Any?]Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: fatal crashCrashes that terminate the processCrashes that terminate the processe: OS-version specificAffects only some versions of the relevant operating systemAffects only some versions of the relevant operating systemfound in release: 3.7Found to occur in 3.7Found to occur in 3.7found in release: 3.9Found to occur in 3.9Found to occur in 3.9has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: pigeonrelated to pigeon messaging codegen toolrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-iosiOS applications specificallyiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version