-
Notifications
You must be signed in to change notification settings - Fork 12
Closed
Description
Describe the Bug
Nullable annotation on ITenantIdentificationStrategy.TryIdentifyTenant is incorrect. It is missing an attribute [NotNullWhen(true)] to follow common try-get-* patterns seen commonly in .NET.
Steps to Reproduce
public void DoSomething(ITenantIdentificationStrategy strategy)
{
if (strategy.TryIdentifyTenant(out var id))
{
Foo(id);
}
}
public void Foo(object input) { }Expected Behavior
No compiler warning.
Actual Behavior
CS8604: Possible null reference argument for parameter 'input'
Additional Info
Mscorelib offers some guidelines intended to be specific to that library but that turn out to be in general good to follow: The api guidelines for that repo say https://github.com/dotnet/runtime/blob/e12e2fa6cbdd1f4b0c8ad1b1e2d960a480c21703/docs/coding-guidelines/api-guidelines/nullability.md?plain=1#L88 and from this the following bullet seems to apply:
- DO annotate non-generic
outreference type arguments onTrymethods as being nullable and with[NotNullWhen(true)](e.g.TryCreate([NotNullWhen(true)] out Semaphore? semaphore)). For non-generic arguments, the argument should be nullable because a failed call will generally storenullinto the argument, and it should be[NotNullWhen(true)]because a successful call will store non-null.
Metadata
Metadata
Assignees
Labels
No labels