Skip to content

Fix crash leaving a tool after switching from New with an empty list - #1245

Merged
mark-sil merged 1 commit into
mainfrom
claude/intelligent-shannon-55fb59
Nov 12, 2026
Merged

mark-sil merged 1 commit into
mainfrom
claude/intelligent-shannon-55fb59

Conversation

@mark-sil

@mark-sil mark-sil commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Switching the UI mode from New to the WinForms view while a detail tool
shows no record now leaves the tool safe to leave or close. Until now
the detail view's DataTree was never set up on that path, so going to
another tool, or closing the window, crashed with a
NullReferenceException in DataTree.SetCurrentSlicePropertyNames.

The DataTree is now set up when the empty tool first shows in the
WinForms view, as it already is when the tool starts in that view or
shows a record.

Reviewer notes

Start here: the no-record branch of ShowRecordOnIdle in
Src/xWorks/RecordEditView.cs -- the whole fix is one call.

What it does. When the Legacy view is active, RecordEditView keeps the
DataTree initialized: SetupDataContext does it at load and the record
branch of ShowRecordOnIdle does it before ShowObject. The no-record branch
only showed, hid and reset the tree, so a New-to-Legacy switch on an empty list
(Grammar > Exception "Features" in Sena 3) left it without Init. Leaving the
tool (XWindow.ChangeContentObjectIfPossible) or closing the window
(ConsideringClosing) then reached DataTree.PrepareToGoAway with a null
property table. That branch now calls EnsureDataTreeInitialized() too.

Where to look.

  • Initializing the tree there also makes it and DTMenuHandler mediator
    targets on an empty list -- the same state as a tool that starts in Legacy
    with an empty list.
  • Pinned by FlipNewToLegacy_WithNoCurrentRecord_PrepareToGoAwaySucceeds in
    RecordEditViewSwitchTests, which fails without the fix with the crash's
    stack.

Deliberately not here. EnsureDataTreeVisible still does not initialize
the tree itself; folding the call in would remove the hand pairing at three
call sites, but is a wider change than the fix needs.

Verification. test.ps1 -CommentHygiene -TokenHygiene on
RecordEditViewSwitchTests and RecordEditViewActiveHostContractTests:
passed. Manual in Sena 3: switching tools after the mode switch, closing the
window after it, and inserting the list's first item after it.

Next: approve.

Preflight review details

Files changed: 2 -- Src/xWorks/RecordEditView.cs,
Src/xWorks/xWorksTests/Avalonia/Hosting/RecordEditViewSwitchTests.cs.

Contract/API changes: none.

Findings: no Critical or Important findings. Minor: moving
EnsureDataTreeInitialized() into EnsureDataTreeVisible() (not taken, see
Reviewer notes); initialization in the no-record branch runs outside the
try/catch (same as SetupDataContext at load); the test does not drive the
window-close path (ConsideringClosing calls the same PrepareToGoAway;
tested by hand).

Validation: targeted tests pass with comment and token hygiene clean; the
manual checks above were run by the author.

🤖 Generated with Claude Code


This change is Reviewable

Switching the UI mode from New to the WinForms view while a detail tool
shows no record now leaves the tool safe to leave or close. Until now
the detail view's DataTree was never set up on that path, so going to
another tool, or closing the window, crashed with a
NullReferenceException in DataTree.SetCurrentSlicePropertyNames.

The DataTree is now set up when the empty tool first shows in the
WinForms view, as it already is when the tool starts in that view or
shows a record.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

NUnit Tests

    1 files  ±0      1 suites  ±0   14m 36s ⏱️ -22s
7 241 tests +1  7 156 ✅ +1  85 💤 ±0  0 ❌ ±0 
7 250 runs  +1  7 165 ✅ +1  85 💤 ±0  0 ❌ ±0 

Results for commit e0dfc25. ± Comparison against base commit ef1a81c.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 40.83%. Comparing base (a1f69e7) to head (e0dfc25).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1245      +/-   ##
==========================================
+ Coverage   40.71%   40.83%   +0.11%     
==========================================
  Files        1569     1573       +4     
  Lines      357048   357160     +112     
  Branches    41782    41812      +30     
==========================================
+ Hits       145386   145851     +465     
+ Misses     182320   182003     -317     
+ Partials    29342    29306      -36     
Files with missing lines Coverage Δ
Src/xWorks/RecordEditView.cs 62.03% <100.00%> (+1.85%) ⬆️

... and 32 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@thejambi thejambi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@thejambi reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on mark-sil).

@mark-sil
mark-sil merged commit facc384 into main Nov 12, 2026
9 checks passed
@mark-sil
mark-sil deleted the claude/intelligent-shannon-55fb59 branch November 12, 2026 15:27
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.

3 participants