[Maintainability] Fix CS8619 nullability mismatch on RabbitMQ message Headers (4 sites) #697

Closed
opened 2026-07-18 02:12:35 +00:00 by spikerj · 1 comment
Owner

Rule: CS8619 (nullability of reference types doesn't match target type) — MAJOR, 4 production sites.

RabbitMQ.Client's BasicProperties.Headers is typed IDictionary<string, object?>?, but four publishers initialize it with new Dictionary<string, object>() (non-nullable value), producing CS8619. The canonical siblings already use object? (NotificationEventPublisher, ScheduledTaskPublisher, RabbitMQRetryHelper).

Sites (all new Dictionary<string, object>new Dictionary<string, object?>):

  • SpikerSoft.Common/Telemetry/ActivityHelper.cs:134 — the shared InjectTraceContext trace-header allocator
  • SpikerSoft.Business/Domain/Calendar/Services/CalendarNotificationService.cs:105
  • SpikerSoft.EventHandlers.QuizGeneration/Services/QuizGenerationWorkerService.cs:839
  • SpikerSoft.EventHandlers.CalendarReminders/Services/CalendarReminderHostedService.cs:276 (Sonar-flagged; introduced by #670's Headers-init NRE fix)

Zero behavior change — nullability is compile-time metadata only; the two forms produce identical IL. All values written are non-null (Encoding.UTF8.GetBytes(...) / boxed int). Purely corrects the annotation to match the target type and clears 4 MAJOR warnings.

**Rule:** CS8619 (nullability of reference types doesn't match target type) — MAJOR, 4 production sites. RabbitMQ.Client's `BasicProperties.Headers` is typed `IDictionary<string, object?>?`, but four publishers initialize it with `new Dictionary<string, object>()` (non-nullable value), producing CS8619. The canonical siblings already use `object?` (`NotificationEventPublisher`, `ScheduledTaskPublisher`, `RabbitMQRetryHelper`). Sites (all `new Dictionary<string, object>` → `new Dictionary<string, object?>`): - `SpikerSoft.Common/Telemetry/ActivityHelper.cs:134` — the shared `InjectTraceContext` trace-header allocator - `SpikerSoft.Business/Domain/Calendar/Services/CalendarNotificationService.cs:105` - `SpikerSoft.EventHandlers.QuizGeneration/Services/QuizGenerationWorkerService.cs:839` - `SpikerSoft.EventHandlers.CalendarReminders/Services/CalendarReminderHostedService.cs:276` (Sonar-flagged; introduced by #670's Headers-init NRE fix) **Zero behavior change** — nullability is compile-time metadata only; the two forms produce identical IL. All values written are non-null (`Encoding.UTF8.GetBytes(...)` / boxed int). Purely corrects the annotation to match the target type and clears 4 MAJOR warnings.
Author
Owner

Resolved in spikersoft-backend PR #392 (merged to master, merge a921ad7c). All four CS8619 sites corrected to Dictionary<string, object?> — annotation-only, zero behavior change. Post-merge master CI green. Closing.

Resolved in spikersoft-backend PR #392 (merged to master, merge a921ad7c). All four CS8619 sites corrected to Dictionary<string, object?> — annotation-only, zero behavior change. Post-merge master CI green. Closing.
Sign in to join this conversation.