Skip to content

DYN-8951: Handle missing group styles and avoid nulls#16985

Merged
zeusongit merged 2 commits into
DynamoDS:masterfrom
zeusongit:DYN-8951
Mar 30, 2026
Merged

DYN-8951: Handle missing group styles and avoid nulls#16985
zeusongit merged 2 commits into
DynamoDS:masterfrom
zeusongit:DYN-8951

Conversation

@zeusongit
Copy link
Copy Markdown
Contributor

Purpose

DocumentationBrowserViewExtension: Use FirstOrDefault when looking up the default group style and only apply an updated GroupStyleItem if a match was found to avoid null reference errors. DynamoModel: When a PreferenceSettings instance is provided with no group styles, populate its GroupStyleItemsList with cloned defaults so hosts/tests providing fresh preferences get sensible default styles.

Declarations

Check these if you believe they are true

Release Notes

Handle missing group styles and avoid nulls. Use FirstOrDefault when looking up the default group style and only apply an updated GroupStyleItem if a match was found

DocumentationBrowserViewExtension: Use FirstOrDefault when looking up the default group style and only apply an updated GroupStyleItem if a match was found to avoid null reference errors. DynamoModel: When a PreferenceSettings instance is provided with no group styles, populate its GroupStyleItemsList with cloned defaults so hosts/tests providing fresh preferences get sensible default styles.
@zeusongit zeusongit requested review from a team and Copilot March 30, 2026 18:50
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

See the ticket for this pull request: https://jira.autodesk.com/browse/DYN-8951

Copy link
Copy Markdown
Contributor

@jasonstratton jasonstratton left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves robustness around group style handling by ensuring default group styles are available when preferences are injected without them, and by making the documentation graph-insert grouping logic tolerant of missing/empty style lists to avoid null/empty-sequence errors.

Changes:

  • Populate PreferenceSettings.GroupStyleItemsList with cloned default group styles when injected preferences contain none.
  • In DocumentationBrowserViewExtension, use FirstOrDefault when selecting a default review style (and fall back to the first available style) and only apply updates when a style is found.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/DynamoCore/Models/DynamoModel.cs Initializes default group styles for injected PreferenceSettings to avoid missing-style scenarios.
src/DocumentationBrowserViewExtension/DocumentationBrowserViewExtension.cs Prevents exceptions when no matching/available group style exists during inserted-graph grouping.

Comment thread src/DynamoCore/Models/DynamoModel.cs Outdated
Comment on lines +1189 to +1190
if (preferences is PreferenceSettings prefs && !prefs.GroupStyleItemsList.Any())
prefs.GroupStyleItemsList = GroupStyleItem.CloneDefaultGroupStyleItems();
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

prefs.GroupStyleItemsList.Any() will throw if GroupStyleItemsList is null (e.g., if a host/test provides a PreferenceSettings instance with the property unset). Consider guarding with a null check and initializing to the cloned defaults when the list is null or empty.

Suggested change
if (preferences is PreferenceSettings prefs && !prefs.GroupStyleItemsList.Any())
prefs.GroupStyleItemsList = GroupStyleItem.CloneDefaultGroupStyleItems();
if (preferences is PreferenceSettings prefs &&
(prefs.GroupStyleItemsList == null || !prefs.GroupStyleItemsList.Any()))
{
prefs.GroupStyleItemsList = GroupStyleItem.CloneDefaultGroupStyleItems();
}

Copilot uses AI. Check for mistakes.
Comment on lines +266 to +267
var groupStyleItem = new GroupStyleItem {Name = styleItem.Name, HexColorString = styleItem.HexColorString};
annotationViewModel.UpdateGroupStyle(groupStyleItem);
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

UpdateGroupStyle reads HexColorString, FontSize, and GroupStyleId from the parameter. Here the new GroupStyleItem only copies Name and HexColorString, so the annotation’s FontSize will become 0 and GroupStyleId will become Guid.Empty even when the selected style had valid values. Consider passing through the existing styleItem (or copying FontSize and GroupStyleId as well).

Suggested change
var groupStyleItem = new GroupStyleItem {Name = styleItem.Name, HexColorString = styleItem.HexColorString};
annotationViewModel.UpdateGroupStyle(groupStyleItem);
// Use the existing style item so that all relevant properties
// such as FontSize and GroupStyleId are preserved.
annotationViewModel.UpdateGroupStyle(styleItem);

Copilot uses AI. Check for mistakes.
Comment on lines 1185 to 1191
if (preferences != null) // If there is preference settings provided...
{
// Ensure default group styles are populated if none are present
// (e.g. when a host or test provides a fresh PreferenceSettings with no styles configured).
if (preferences is PreferenceSettings prefs && !prefs.GroupStyleItemsList.Any())
prefs.GroupStyleItemsList = GroupStyleItem.CloneDefaultGroupStyleItems();
return preferences;
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

This change introduces new initialization behavior when a PreferenceSettings instance is injected via IStartConfiguration.Preferences with no group styles configured. Please add/adjust a unit test that starts DynamoModel with a fresh PreferenceSettings (empty/null GroupStyleItemsList) and asserts the defaults are populated, to prevent regressions in host/test scenarios.

Copilot generated this review using guidance from repository custom instructions.
Ensure PreferenceSettings receives default group styles when GroupStyleItemsList is null or empty by updating CreateOrLoadPreferences to check for null before cloning defaults. Simplify DocumentationBrowserViewExtension to pass the existing GroupStyleItem directly to UpdateGroupStyle instead of recreating a new instance. Add a unit test (WhenPreferencesHaveEmptyGroupStylesListThenDefaultsArePopulated) to verify defaults are injected when preferences start with an empty list.
@sonarqubecloud
Copy link
Copy Markdown

@zeusongit zeusongit merged commit b8fce22 into DynamoDS:master Mar 30, 2026
27 of 29 checks passed
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.

4 participants