Skip to content

Fix NullReferenceException and crash in ManifestExtensions#182

Merged
rmarinho merged 2 commits into
mainfrom
fix/manifest-extensions-null-ref
Jun 1, 2026
Merged

Fix NullReferenceException and crash in ManifestExtensions#182
rmarinho merged 2 commits into
mainfrom
fix/manifest-extensions-null-ref

Conversation

@rmarinho
Copy link
Copy Markdown
Member

Summary

Fixes two bugs in ManifestExtensions:

  1. NullReferenceException in GetWKAppBundleIdentifier / SetWKAppBundleIdentifier — these methods called GetNSExtensionAttributes() which can return null, then immediately dereferenced the result without a null check.

  2. ArgumentOutOfRangeException in ParseDeviceFamilyFromNumber — throws for unknown device family numbers (e.g. from newer Xcode plists), crashing GetUIDeviceFamily. Now logs a warning and returns a safe fallback, consistent with how the string parser already handles unknown values.

Testing

Added ManifestExtensionsTests with 6 tests covering both null/missing dictionary cases and unknown device family handling.

Copilot AI review requested due to automatic review settings May 29, 2026 15:10
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

Fixes robustness issues in Xamarin.MacDev manifest parsing/extensions to avoid crashes when expected plist structures or device family values are missing/unknown.

Changes:

  • Avoids NullReferenceException in WatchKit bundle identifier getters/setters when NSExtensionAttributes is absent.
  • Prevents ArgumentOutOfRangeException when parsing unknown numeric UIDeviceFamily entries by logging and using a fallback.
  • Adds NUnit coverage for the above scenarios.

Reviewed changes

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

File Description
Xamarin.MacDev/ManifestExtensions.cs Adds null-guarding for NSExtensionAttributes access and changes unknown numeric device-family handling to warn + fallback.
tests/ManifestExtensionsTests.cs Adds tests for missing extension dictionaries and unknown/known UIDeviceFamily parsing behavior.

Comment thread Xamarin.MacDev/ManifestExtensions.cs Outdated
Comment thread Xamarin.MacDev/ManifestExtensions.cs Outdated
Comment thread tests/ManifestExtensionsTests.cs Outdated
- GetWKAppBundleIdentifier: handle null from GetNSExtensionAttributes.
- SetWKAppBundleIdentifier: auto-create NSExtension/NSExtensionAttributes
  structure when setting a non-empty value (avoid silent no-op).
- ParseDeviceFamilyFromNumber → TryParseDeviceFamilyFromNumber: unknown
  device family numbers are now logged and skipped (not coerced to IPhone),
  consistent with how the string parser already handles unknown values.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rmarinho rmarinho force-pushed the fix/manifest-extensions-null-ref branch from 7d5ea0a to 214ee0c Compare May 29, 2026 15:42
Changed 'Skipped unknown device family' to 'Ignoring unrecognized device family number'
to make it clear the value is not mapped to any family and is simply discarded.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rmarinho rmarinho merged commit ac7f924 into main Jun 1, 2026
7 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.

3 participants