Skip to content

fix: factory fetch NRE when [Fetch] returns false with [AuthorizeFactory]#47

Merged
keithdv merged 2 commits intomainfrom
fix/factory-fetch-nre-on-not-found
Mar 21, 2026
Merged

fix: factory fetch NRE when [Fetch] returns false with [AuthorizeFactory]#47
keithdv merged 2 commits intomainfrom
fix/factory-fetch-nre-on-not-found

Conversation

@keithdv
Copy link
Contributor

@keithdv keithdv commented Mar 21, 2026

Summary

  • Fix NullReferenceException in generated factory Fetch methods when [Fetch] returns false (entity not found) and the factory has [AuthorizeFactory<T>]
  • Two sites in ClassFactoryRenderer.cs now emit new Authorized<T>() instead of default! on the bool-false path when HasAuth is true
  • 4 new integration tests covering auth + bool-false (local, remote, with service injection) and auth + bool-true (regression guard)
  • Bump version to 0.23.1

Test plan

  • All 1,984 existing tests pass (no regressions)
  • New tests: RemoteFetch_AuthBoolFalse_ServerReturnsNull, RemoteFetch_AuthBoolFalse_ClientReturnsNull, RemoteFetch_AuthBoolTrue_ReturnsObject, RemoteFetch_RemoteAuthBoolFalse_ReturnsNull

🤖 Generated with Claude Code

keithdv and others added 2 commits March 21, 2026 15:52
…ory]

Generated factory Fetch methods threw NullReferenceException when the
underlying [Fetch] method returned false (entity not found) and the
factory had [AuthorizeFactory<T>]. The bool-false path emitted
`return default!` which is null for Authorized<T>, then the public
wrapper dereferenced .Result on the null reference.

Fixed by emitting `new Authorized<T>()` instead of `default!` when
HasAuth is true, at both the read-style and write-style local method
sites. This returns a non-null wrapper with HasAccess=false and
Result=null, so .Result returns null correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@keithdv keithdv merged commit df861c2 into main Mar 21, 2026
2 checks passed
@keithdv keithdv deleted the fix/factory-fetch-nre-on-not-found branch March 21, 2026 21:30
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.

1 participant