Skip to content

Add [NotNull] annotation and explanation to ImapClient.Inbox#1996

Closed
campbell-reid-displayr wants to merge 1 commit intojstedfast:masterfrom
campbell-reid-displayr:inbox-notnull-annotation
Closed

Add [NotNull] annotation and explanation to ImapClient.Inbox#1996
campbell-reid-displayr wants to merge 1 commit intojstedfast:masterfrom
campbell-reid-displayr:inbox-notnull-annotation

Conversation

@campbell-reid-displayr
Copy link
Copy Markdown

Summary

  • ImapClient.Inbox is typed as IMailFolder? to match the nullable ImapEngine.Inbox field, but the property never actually returns null in practice
  • Adds [NotNull] so the compiler can surface this guarantee to callers using the concrete ImapClient type, eliminating spurious null warnings
  • Adds a comment explaining the reasoning with permalinks to the relevant code

Why it never returns null

  1. CheckAuthenticated() throws ServiceNotAuthenticatedException before engine.Inbox is ever reached if the client is unauthenticated
  2. Authenticate() calls OnAuthenticated()QuerySpecialFolders() synchronously before returning, which always assigns engine.Inbox — creating a placeholder folder if the server never reported one (ImapEngine.cs#L3762-L3768)
  3. engine.Inbox is never reassigned null after that point

Test plan

  • Existing IMAP unit tests pass
  • Callers accessing ImapClient.Inbox directly no longer receive a nullable warning from the compiler

🤖 Generated with Claude Code

The property is typed as IMailFolder? to match the nullable underlying
ImapEngine.Inbox field, but it never returns null in practice — it throws
ServiceNotAuthenticatedException before reaching engine.Inbox, and
QuerySpecialFolders() guarantees engine.Inbox is non-null before
Authenticate() returns. The [NotNull] attribute surfaces this guarantee
to the compiler for callers using the concrete type.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jstedfast
Copy link
Copy Markdown
Owner

The problem is that it can return null in several situations:

  1. The client isn't connected and authenticated
  2. The server is broken and does not list Inbox in the LIST response

@jstedfast
Copy link
Copy Markdown
Owner

Ah, looks like I wrote a workaround for the second situation

@jstedfast
Copy link
Copy Markdown
Owner

Ok, I guess we can...

jstedfast added a commit that referenced this pull request Apr 23, 2026
@jstedfast jstedfast closed this Apr 23, 2026
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