Can the NSArray.FromNSObjects really return null? · Issue #19622 · dotnet/macios (original) (raw)
Here we can see that the factory method NSArray<T>.FromNSObjects
returns a value marked as nullable NSArray<TKey>?
. But from the implementation logic, I can't see any normal way for it to return null
. The only suspicious point is
https://github.com/xamarin/xamarin-macios/blob/1173c016b7aecc98e5b9ec6fd6ca07e0a5d4e9eb/src/Foundation/NSArray_1.cs#L73-L74
(then arr
is returned as the function result).
The GetNSObject
can indeed return null
. But is it possible in this particular case where we just created the object the line above and then tried to get the object for it? It looks like we should get a 100% non-null result here (and if not, then something went completely wrong, so an assert or exception might be a good idea).
The changes which make the return value nullable were introduced here somewhere here b945c2d, but I didn't find any explanation why it was done this way.
My other assumption that it may be something belongs to the #9592, when the underlying native object was somehow destroyed, but I'm unsure and anyway it looks like a little bit strange.