Repository navigation
Fix NullReferenceException when InputSelect (multiple) has no selection - #66868
irfanajaffer wants to merge 64 commits into
Conversation
|
Thanks for your PR, @irfanajaffer. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
@dotnet-policy-service agree company="Syncfusion, Inc." |
There was a problem hiding this comment.
When this feature landed, #33950, E2E tests were added. Let's patch their coverage in this PR with a null array test -> next to
Beyond that, I'm thinking if null is really better than "[]". Is there a specific case when differentiation between never-selected from all-unseleced matters?
There was a problem hiding this comment.
🟡 Changes recommended
The collection converter changes missing form data from null to an empty array, allowing omitted required arrays to pass validation and bypassing application defaults that depend on null.
1 open issue
9 resolved since last review
Typing into the field won't clear the custom validation message because… After adding a validation message programmatically, the username field has validation errors but is…ValidationMessageStoreis not thread-safe and is being mutated on a threadpool thread. Marshal… This test is specifically validating a null array binding scenario, but the generic type arguments…StringArrayis assigned null in the new test. Declaring it non-nullable forces… This assigns null to a non-nullableobjectlocal, which will produce an NRT warning in… This array literal contains a null element, which doesn't match the declared element nullability of… In a nullable-enabled codebase, assigning null to non-nullable locals will produce NRT warnings… Prefer pattern matching (is null) over== nullfor null checks to align with the repo's…
Review effort: Balanced
|
/review |
There was a problem hiding this comment.
🟡 Changes recommended
A duplicate test declaration prevents compilation, the null-formatting guard regresses scalar and custom-converter behavior, and missing-array handling conflicts with the expected null contract and new test assertions.
3 open issues
1 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
Source-only review of frozen head f779fe0a164810986df7333302f78a7e556defa3 found one verified build blocker and surfaced two verifier-gated unresolved candidates inline.
- Verified: duplicate
FormatValue_Array_Null()methods prevent the Components test project from compiling. - Unresolved: whether the public generic null short-circuit changes custom
TypeConverteroutput depends on target-version BCL dispatch evidence not present in the bundle. - Unresolved: whether the new
int[]no-elements assertion reaches the empty-array branch depends on the assignedFormDataReaderpath or immutable validation evidence.
Existing feedback already covers the separate missing-array semantic concern at discussion 4466972422: omitted arrays becoming empty can affect required validation and null-based application defaults. Deduplication is neutral and does not endorse or resolve that thread.
Both routed guides completed their in-scope source checks using gpt-5.6-sol: docs/CrossCuttingGuidance.md and docs/BlazorComponentsGuidance.md. Security assessment and execution of builds, tests, CI, browsers, samples, trimming, or runtime behavior were excluded. Material changes were covered by the routed guides; no additional specialist guide covered FormMapping as a standalone domain.
Provenance: version-2 frozen bundle; head f779fe0a164810986df7333302f78a7e556defa3; merge base 1c94b15aa54d3d490d0ee060b7d496db3cb291e7; base tip and immutable guidance source 2bf69e1acc6a6418b4278b90873665891752cc16. This is source-only proof, not runtime validation. Frozen feedback only was observable; feedback posted after bundle preparation was not checked.
Generated by ASP.NET Core Pull Request Review for #66868 · copilot · gpt56 · 336.8 AIC · ⌖ 8.54 AIC · ⊞ 20.1K
Comment /review to run again
|
The local G/S/O panel completed at Informational only Each item below is non-blocking: Posted for informational purposes so the author can confirm the verifier didn't discard or leave unresolved a real finding; this item does not block
Untested coverage gaps, separate from those discarded checks: The arms identified no dedicated test for non-null -> null followed by option insertion, or for the Minimal API The mapper assertion and custom-TypeConverter uncertainties are already posted here and here, so they are not repeated. Validation boundary: all three arms used frozen source only; no local product build, test, or browser execution was performed. Human-directed and GitHub Copilot-generated. |
|
Hi @PureWeen , Thanks for the review. I've addressed the reviewer concerns that were identified as source-supported:
Regarding the informational notes:
The intent of the final patch is to keep the fix narrowly scoped to the InputSelect multiple-selection null scenario while preserving existing formatting and form-mapping behavior. |
Each rule covers a defect a human reviewer found on a real open PR that PR Buddy missed: - PRB018: a load guard is set inside a try before later work that can fail, so the early return blocks every retry (LykosAI/StabilityMatrix#1795) - PRB019: a new collection field of objects that only grows, or is only cleared in another method (dotnet/winforms#13953) - PRB020: a [Flags] enum member whose value isn't a single bit (DapperLib/Dapper#1590) - PRB105: a test looks up a non-public member through reflection (dotnet/aspnetcore#66868) None of them fires on the other compared PRs. PRB019 skips memo caches that are read in the same method that adds to them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
/review |
|
Copilot's local review panel found no issues to raise at this commit. The GPT-5.6 Sol, GPT-6.1 Sol, and Opus 5.5 arms completed their reviews of Informational notes, not change requests
Posted for informational purposes so the author can confirm the verifier didn't discard or leave unresolved a real finding; this item does not block No concrete provisional finding required a candidate-verifier invocation. Untested coverage boundaries, separate from discarded checks: direct setter calls and ordinary empty-array deselection are not independent proof of the null-array fix. No dedicated new populated-to-null-then-option-insertion test was identified; source consumer guards were assessed instead. FormMapping was covered by the two routed guides, not a standalone specialist. Validation boundary: all three arms assessed frozen source and test coverage; no local product build, test, or browser execution was performed. Human-directed and GitHub Copilot-generated. |
|
@ilonatommy, the current head adds an SSR E2E test for the reported scenario. It deselects all options for a |
|
Could we keep this focused on the null-array rendering failure? The CollectionConverter and DictionaryConverter changes also affect how missing nested collections are mapped. Can we avoid that behavior change or handle it separately? |



Description:
When data-binding to an array type in a Blazor component (for example using @Bind with a property of type T[]), formatting a null array value could throw a NullReferenceException. The exception occurred because the FormatArrayValue delegate inside BindConverter.MakeArrayFormatter() accessed the array's Length (value.Length) without first checking whether value was null.
This change adds a null-guard at the start of the FormatArrayValue local function in BindConverter.cs:
if (value is null) return null;
This short-circuits formatting for uninitialized arrays and prevents the NullReferenceException when resolving the string representation during component parameter binding.
Root Cause
The local FormatArrayValue function assumed the incoming array was non-null and immediately accessed value.Length and iterated the elements. When a bound array property was null, this access caused a NullReferenceException. A simple null-check was missing at the start of the formatter.
Testing
Added a unit test that exercises the array formatter with a null array input and asserts that:
No exception is thrown when formatting a null array.
The formatter returns null (or the expected string representation for null per contract).
Verified existing binding tests still pass.
Fixes #54431