Fix WriteArray in encoders to also write null.#3266
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3266 +/- ##
==========================================
+ Coverage 57.64% 57.85% +0.21%
==========================================
Files 365 365
Lines 79419 79423 +4
Branches 13865 13870 +5
==========================================
+ Hits 45780 45950 +170
+ Misses 29382 29302 -80
+ Partials 4257 4171 -86 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a null reference exception in encoder implementations by updating the WriteArray methods to properly handle null arrays for Variant and Enumeration types. Previously, the encoders would crash when encountering null arrays in these specific cases.
- Added null checks for Variant and Enumeration array types in all three encoder implementations
- Refactored conditional logic to use pattern matching with
is null or Type[]syntax - Added comprehensive test coverage for null array encoding/decoding scenarios
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Tests/Opc.Ua.Core.Tests/Types/Encoders/EncoderTests.cs | Adds new test method EncodeNullArray to verify null array handling across all encoder types |
| Stack/Opc.Ua.Core/Types/Encoders/XmlEncoder.cs | Updates WriteArray to handle null arrays for Variant and Enumeration types using pattern matching |
| Stack/Opc.Ua.Core/Types/Encoders/JsonEncoder.cs | Updates WriteArray to handle null arrays for Variant and Enumeration types using pattern matching |
| Stack/Opc.Ua.Core/Types/Encoders/BinaryEncoder.cs | Updates WriteArray to handle null arrays for Variant and Enumeration types using pattern matching |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Will handle the issue in separate tracked issue.
Proposed changes
WriteArray needs to handle null object in variant case (and enumeration) which it does not today, while all other types correctly write a null. Instead it crashes with null ref when used with Complex type system.
Related Issues
Types of changes
What types of changes does your code introduce?
Put an
xin the boxes that apply. You can also fill these out after creating the PR.Checklist
Put an
xin the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments
The change was tested against the simulation server: