Skip to content

Fix overstatement about nullable reference types runtime protection #47090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 3, 2025

The tutorial incorrectly stated that non-nullable reference type variables "can't be null" at runtime, which is misleading. While nullable reference types provide valuable compile-time warnings, they cannot prevent null values at runtime, especially for public APIs.

Changes Made

Primary fix (line 127):

  • Before: "Its value can't be null."
  • After: "While the compiler warns about potential null assignments, runtime null values are still possible. For public APIs, consider adding argument validation even for non-nullable reference types, since client code might not have nullable reference types enabled or could intentionally pass null."

Secondary improvement (line 206):

  • Added clarification that "The compiler's static analysis helps ensure these design contracts are followed" to be more precise about the compiler's role.

Why This Matters

The original statement was problematic because:

  1. Compiler warnings ≠ runtime protection
  2. Public APIs can receive null values from callers who haven't opted into nullable reference types
  3. Malicious or careless code can still pass null values
  4. The overstatement could lead developers to skip necessary argument validation

The corrected documentation now accurately explains the relationship between compile-time analysis and runtime behavior, while providing practical guidance for public API design.

Fixes #22704.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Jul 3, 2025
@Copilot Copilot AI changed the title [WIP] Article contains wrongful information Fix overstatement about nullable reference types runtime protection Jul 3, 2025
@Copilot Copilot AI requested a review from BillWagner July 3, 2025 16:09
Copilot finished work on behalf of BillWagner July 3, 2025 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-csharp/svc fundamentals/subsvc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Article contains wrongful information
2 participants