Add support for nullable reference types - Serialization#7859
Conversation
| }); | ||
| } | ||
|
|
||
| static IMessageSerializer CreateMessageSerializer(Tuple<SerializationDefinition, SettingsHolder> definitionAndSettings, IMessageMapper mapper, IReadOnlySettings mainSettings) |
There was a problem hiding this comment.
Are we sure mapper or mainSettings cannot be null?
There was a problem hiding this comment.
Wrt to mapper, it cannot be null:
As per line 20
var mapper = context.Settings.Get<IMessageMapper>();
Get() (SettingsHolder.cs:68-71) delegates to Get(string key) (SettingsHolder.cs:78-92), which throws KeyNotFoundException if the key is missing .
So this call either returns a real IMessageMapper or the method never reaches the assignment.
Also the key is always registered before this runs: EndpointConfiguration's constructor and calls Settings.SetDefault(...) for every endpoint, before any Feature.Setup executes. So SerializationFeature always finds it already registered.
There was a problem hiding this comment.
Wrt to mainSettings,
context.Settings, is sourced from FeatureConfigurationContext.Settings, with { get; } only property set once in that class's internal constructor. Being internal means it can only be constructed by our own code, not by user code
But there is one internal place that does create it, and it never passes null. It feeds it a settings object that's already being used successfully on several lines just above it. If that settings object were null, the program would've already crashed before even reaching that point.
So mainSettings can't be null either.
| /// </param> | ||
| /// <returns>Deserialized messages.</returns> | ||
| object[] Deserialize(ReadOnlyMemory<byte> body, IList<Type> messageTypes = null); | ||
| object[] Deserialize(ReadOnlyMemory<byte> body, IList<Type>? messageTypes = null); |
There was a problem hiding this comment.
The messageTypes is already defaulted to null, so the ? is just making the annotation honest about behavior that already existed
This PR enables
#nullable enableon the files in the folder, and removes the following fromNullableAnnotations.ApproveNullableTypes.approved.txt