Skip to content

Reject a saved state that contains null items [patch] - #63

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/reject-null-state-items
Sep 28, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/reject-null-state-items

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #60

What changed

NavigationState<T>'s constructor checked currentIndex but not the items themselves. A state file like {"items":[null],"currentIndex":0} loaded fine, and the next SaveStateAsync crashed with a NullReferenceException.

The constructor now throws ArgumentException when any item is null. JsonFilePersistenceProvider.LoadStateAsync already turns an ArgumentException into a null result, so NavigationStack.LoadStateAsync now returns false and leaves the stack as it was.

Tests

  • New test LoadStateAsync_NullItem_ReturnsFalseAndLeavesStackUnchanged. It fails on main and passes with this change.
  • The full suite passes locally (15/15).

🤖 Generated with Claude Code

https://claude.ai/code/session_01ScKzvHsZwsrSifP4Mbp1jW


Generated by Claude Code

NavigationState's constructor validated the index but not the items, so
{"items":[null],"currentIndex":0} loaded successfully and the next
SaveStateAsync crashed with a NullReferenceException. The constructor now
throws ArgumentException for a null item, which JsonFilePersistenceProvider
already turns into a null load, so LoadStateAsync returns false and leaves
the stack unchanged.

Fixes #60

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ScKzvHsZwsrSifP4Mbp1jW
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 2cee749 into main Sep 28, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the fix/reject-null-state-items branch September 28, 2026 08:59
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.

LoadStateAsync accepts a saved state containing null items, and the next SaveStateAsync throws NullReferenceException

2 participants