-
Notifications
You must be signed in to change notification settings - Fork 436
Fix NullReferenceException when importing UST with unregistered flags #1909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a NullReferenceException that occurs when importing UST files containing flags that are not registered in the project's expression list. The fix adds a null check before attempting to clone expression descriptors.
Key changes:
- Added null check for expression lookup result before cloning
- Unregistered flags are now silently ignored instead of causing a crash
- Added explanatory comments about the behavior
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // otherwise expression not found, often when importing UST into a new project | ||
| // ignore it. |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is grammatically incomplete. It should be a complete sentence with proper capitalization and punctuation.
| // otherwise expression not found, often when importing UST into a new project | |
| // ignore it. | |
| // Otherwise expression not found, often when importing UST into a new project. | |
| // Ignore it. |
| foreach (var flag in parser.Parse(parts[1].Trim())) { | ||
| var descriptor = project.expressions.Values.FirstOrDefault(exp => exp.flag == flag.Key).Clone(); | ||
| descriptor.CustomDefaultValue = flag.Value; | ||
| track.TrackExpressions.Add(descriptor); | ||
| var item = project.expressions.Values.FirstOrDefault(exp => exp.flag == flag.Key); | ||
| if (item != null) { | ||
| var descriptor = item.Clone(); | ||
| descriptor.CustomDefaultValue = flag.Value; | ||
| track.TrackExpressions.Add(descriptor); | ||
| } | ||
| // otherwise expression not found, often when importing UST into a new project | ||
| // ignore it. | ||
| } |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bug fix lacks test coverage. Consider adding a test case that verifies the handling of unregistered flags when importing UST files, ensuring that no NullReferenceException is thrown and that unknown flags are silently ignored.
|
This was already fixed in #1864 |
Summary
This PR fixes a
System.NullReferenceExceptionthat occurs when parsing UST flags that are not registered in the project's expressions list.The Bug
When importing UST with flag into a new UProject, the parser identifies flags correctly, but the
FirstOrDefaultalways returnsnullsince no expressions are registered to the project.The Fix
Added a null check before cloning the expression descriptor. If an expression/flag is registered, it is now safely ignored.
Future Improvements / Suggestions
Since I am not very familiar with C#, I only fixed the crash with minimum modification. However, silently ignoring unknown flags is not ideal. A better long-term solution would be to implement a Flag Mapping Popup . When importing a UST with unknown flags, the user could be prompted to manually map them to valid/registered USTX flags.