镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[Microsoft.Android.Build.BaseTasks] Guard against null parent directory in GetNativeLibraryAbi - #13064

Merged
simonrozsival merged 8 commits into
dotnet:mainfrom
austinaviv:fix-13063-getnativelibraryabi-null-parent
Oct 13, 2026
Merged

simonrozsival merged 8 commits into
dotnet:mainfrom
austinaviv:fix-13063-getnativelibraryabi-null-parent

Conversation

@austinaviv

@austinaviv austinaviv commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Context: #13063

Guard against null parent directory in AndroidRidAbiHelper.GetNativeLibraryAbi (fixes #13063):
When resolving the ABI for native libraries located directly at filesystem or drive roots (for instance C:\libfoo.so or /libfoo.so), Directory.GetParent or dir.Parent can be null, causing dir.Parent.Name to throw a NullReferenceException. Added #nullable enable, null checks on dir and pattern matching on dir.Parent before inspecting their names, returning null if no matching ABI can be determined. Added unit tests covering rooted paths, root directories, and ITaskItem instances.

Fixes #13063.

@austinaviv

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

…ry in GetNativeLibraryAbi

AndroidRidAbiHelper.GetNativeLibraryAbi threw a NullReferenceException when resolving native library items placed at root directories (such as C:\libfoo.so or /libfoo.so).

When the immediate containing directory does not match a known ABI name, the helper checks the parent directory to detect RIDs like android-arm64/native. For rooted paths or filesystem roots, Directory.GetParent or dir.Parent can be null, causing dir.Parent.Name to throw a NullReferenceException.

Add null checks for both dir and dir.Parent before inspecting their names, returning null if no ABI can be determined. Add unit test coverage for rooted paths and task items.

Fixes: dotnet#13063
austinaviv and others added 2 commits October 11, 2026 17:12
…kTrace throws (dotnet#13066)

When constructing a Java.Lang.Throwable wrapper or activating via typemap with DoNotRegister, SetJavaStackTrace invokes printStackTrace in Java. If that call throws an exception, the constructor terminates without returning an instance to the caller.

Because SetHandle did not catch exceptions around SetJavaStackTrace, the peer wrapper was never disposed, leaking the global reference created by Construct. Additionally, when DoNotRegister was not passed, the broken instance remained registered in ValueManager.

Wrap SetJavaStackTrace in a try/catch block inside Throwable.SetHandle and call Dispose() on this before re-throwing. This releases the allocated GREF and unregisters the peer, fixing the stage 4 failures in RuntimeExceptionLookupFailureReleasesInput.

Fixes dotnet#13066.
Comment thread src/Mono.Android/Java.Lang/Throwable.cs Resolved

@simonrozsival simonrozsival left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the redundant try-catch block. Otherwise, it looks reasonable.

austinaviv and others added 3 commits October 12, 2026 22:58
…5->36

The macOS CI runner only has platforms;android-36 installed.
compileSdk 35 caused Gradle to fail with:
  Failed to find Platform SDK with path: platforms;android-35
Fixes the APKs 2 package test failure in PR dotnet#13064.
@simonrozsival
simonrozsival merged commit 1f88b1d into dotnet:main Oct 13, 2026
42 checks passed
@simonrozsival

Copy link
Copy Markdown
Member

/backport to release/11.0.1xx

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0.1xx (link to workflow run)

jonathanpeppers pushed a commit that referenced this pull request Oct 13, 2026
…ry in GetNativeLibraryAbi (#13064) (#13099)

Context: #13063

Guard against null parent directory in `AndroidRidAbiHelper.GetNativeLibraryAbi` (fixes #13063):
When resolving the ABI for native libraries located directly at filesystem or drive roots (for instance `C:\libfoo.so` or `/libfoo.so`), `Directory.GetParent` or `dir.Parent` can be null, causing `dir.Parent.Name` to throw a `NullReferenceException`. Added `#nullable enable`, null checks on `dir` and pattern matching on `dir.Parent` before inspecting their names, returning null if no matching ABI can be determined. Added unit tests covering rooted paths, root directories, and `ITaskItem` instances.

Fixes #13063.

Co-authored-by: Austin <abhikr6714@gmail.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullReferenceException in AndroidRidAbiHelper.GetNativeLibraryAbi for rooted paths

3 participants