Repository navigation
Fix crash leaving a tool after switching from New with an empty list - #1245
Merged
Merged
Conversation
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>
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
thejambi
approved these changes
Nov 12, 2026
thejambi
left a comment
Contributor
There was a problem hiding this comment.
@thejambi reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on mark-sil).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ShowRecordOnIdleinSrc/xWorks/RecordEditView.cs-- the whole fix is one call.What it does. When the Legacy view is active,
RecordEditViewkeeps theDataTreeinitialized:SetupDataContextdoes it at load and the recordbranch of
ShowRecordOnIdledoes it beforeShowObject. The no-record branchonly 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 thetool (
XWindow.ChangeContentObjectIfPossible) or closing the window(
ConsideringClosing) then reachedDataTree.PrepareToGoAwaywith a nullproperty table. That branch now calls
EnsureDataTreeInitialized()too.Where to look.
DTMenuHandlermediatortargets on an empty list -- the same state as a tool that starts in Legacy
with an empty list.
FlipNewToLegacy_WithNoCurrentRecord_PrepareToGoAwaySucceedsinRecordEditViewSwitchTests, which fails without the fix with the crash'sstack.
Deliberately not here.
EnsureDataTreeVisiblestill does not initializethe 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 -TokenHygieneonRecordEditViewSwitchTestsandRecordEditViewActiveHostContractTests: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()intoEnsureDataTreeVisible()(not taken, seeReviewer notes); initialization in the no-record branch runs outside the
try/catch (same as
SetupDataContextat load); the test does not drive thewindow-close path (
ConsideringClosingcalls the samePrepareToGoAway;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