[ObjCRuntime] Enable nullability and clean up Runtime.#24747
[ObjCRuntime] Enable nullability and clean up Runtime.#24747rolfbjarne wants to merge 1 commit intomainfrom
Conversation
This is file 7 of 7 files with nullability disabled in ObjCRuntime.
* Enable nullability for Runtime.cs by removing the file-level nullable-disable section.
* Remove placeholder XML comments ("To be added.") and replace them with concrete documentation.
* Normalize XML documentation spacing and fix documentation wording for updated members.
* Add null argument validation for GetINativeObject (IntPtr, bool, Type).
Contributes towards #17285.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This pull request enables nullability for Runtime.cs, the final file in the ObjCRuntime namespace that had nullability disabled. The changes improve type safety, remove placeholder documentation, and normalize XML documentation formatting across the file.
Changes:
- Removed
#nullable disabledirective and related pragma warnings to enable nullability for Runtime.cs - Added defensive null checks for GetNSObject and GCHandle.FromIntPtr().Target in exception marshaling methods
- Updated delegate signatures in Registrar.cs and Exceptions.cs to mark sender parameters as nullable (object?)
- Replaced all "To be added" placeholder XML documentation with concrete, helpful descriptions
- Normalized XML documentation indentation and spacing for consistency
- Applied modern C# patterns (out var, pattern matching) for improved readability
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/ObjCRuntime/Runtime.cs | Enabled nullability, added null safety checks in exception marshaling, improved documentation, modernized code patterns |
| src/ObjCRuntime/Registrar.cs | Updated AssemblyRegistrationHandler delegate to use nullable sender parameter |
| src/ObjCRuntime/Exceptions.cs | Updated exception handler delegates to use nullable sender parameters |
Comments suppressed due to low confidence (1)
src/ObjCRuntime/Runtime.cs:1933
- The PR description mentions "Add null argument validation for GetINativeObject (IntPtr, bool, Type)", but the target_type parameter is not validated for null. This parameter is a reference type and is used without null checking at line 1948 (target_type.IsAssignableFrom). Consider adding null validation at the start of the method:
if (target_type is null) throw new ArgumentNullException (nameof (target_type));
public static INativeObject? GetINativeObject (IntPtr ptr, bool owns, Type target_type)
{
return GetINativeObject (ptr, owns, target_type, null);
}
✅ [CI Build #5284b54] Build passed (Build packages) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #5284b54] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #5284b54] Build passed (Detect API changes) ✅Pipeline on Agent |
|
🔥 Unable to find the contents for the comment: D:\a\1\s\change-detection\results\gh-comment.md does not exist :fire Pipeline on Agent |
🔥 [CI Build #5284b54] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 1 tests failed, 155 tests passed. Failures❌ linker tests [attempt 3]1 tests failed, 43 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
This is file 7 of 7 files with nullability disabled in ObjCRuntime.
Contributes towards #17285.