Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@plioi
Copy link
Contributor

@plioi plioi commented Dec 17, 2023

PipeMessage message deserialization has until now worked by calling JsonSerializer.Deserialize<T>(string) directly, which can return null in the case that the incoming string is the json literal "null". This has two unfortunate consequences:

  1. Callers need to insist that the result for pipe messages in particular is not null by marking the call site with !, or else the nullability could spread from there.
  2. In order to do so confidently, all calls to JsonSerializer.Deserialize<T>(string) need to be reviewed, whether relevant to these pipe messages or not, in order to instill the confidence to declare ! accurately. In fact, all of the pipe messages deserialized come from sources that would not be null during serialization, but it's been a nontrivial analysis each time.

This PR formalizes the path to serialize and deserialize PipeMessage types, giving the opportunity to check for null and fail fast, allowing this Deserialize method to be declared as returning a non-null message, letting call sites omit the risky ! assertion.

…erializer.Serialize|Deserialize where the types involved are PipeMessage types, as a step towards taking further control over these code paths.
… helper methods defined on PipeMessage, as a step towards taking further control over these code paths.
…ipated case that the message is the JSON literal `null`, allowing all code paths to confidently work with non-null type declarations.
@plioi plioi marked this pull request as ready for review December 17, 2023 00:40
@plioi plioi merged commit 7bfd14a into main Dec 17, 2023
@plioi plioi deleted the non-null-pipe-deserialization branch December 17, 2023 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants