Repository navigation
Honor DoNotRegister for Java.Lang.Throwable handles - #13052
Merged
simonrozsival merged 2 commits intoOct 10, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The fix matches the existing ownership conversion contract and has comprehensive regression coverage; the inline suggestion is non-blocking.
1 open finding
What changed in this PR
Updates Throwable JNI peer construction to honor DoNotRegister, preventing premature registry replacement during typemap activation.
Changes:
- Preserves
DoNotRegisterwhile retaining copy semantics. - Adds ownership, replaceable-peer, and reentrant-alias regression tests.
| File | Description |
|---|---|
src/Mono.Android/Java.Lang/Throwable.cs |
Converts ownership flags into appropriate JNI reference options. |
tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/TransferredReferenceTests.cs |
Adds regression coverage and flag-aware reference tracking. |
🧠 Review effort: Balanced
Comment on lines
+434
to
+435
| BeforeConstruct?.Invoke (handle); | ||
| return handle; |
Member
Author
|
@dalexsoto review |
dalexsoto
approved these changes
Oct 9, 2026
dalexsoto
left a comment
Member
There was a problem hiding this comment.
Throwable construction now preserves DoNotRegister without changing reference-copy or transferred-input cleanup semantics. Typemap activation and reentrant lookup retain the existing peer winner; the complete correctness and integration review leaves no blocking issue.
simonrozsival
enabled auto-merge (squash)
October 10, 2026 05:34
simonrozsival
deleted the
simonrozsival-throwable-registration-contract
branch
October 10, 2026 06:14
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Pull Request
Java.Lang.Throwable.SetHandleignoredJniHandleOwnership.DoNotRegisterand always registered its wrapper. This caused premature registry insertion during typemap activation, before the peer was markedReplaceable, and could displace an existing peer; a reentrant lookup could similarly lose its alias as winner.SetHandlenow passesJNIEnv.ToJniObjectReferenceOptions(transfer)for non-null references while retainingNonefor null. This preserves the wrapper's copy semantics and leaves raw transferred-input cleanup unchanged. The regression tests cover normal registration, borrowed/local/global inputs with combined raw ownership andDoNotRegisterflags, existing replaceable-peer preservation, and reentrant alias identity.Validation
ThrowableConstructionHonorsDoNotRegisterfor threeDoNotRegisterownership cases,ThrowableActivationPreservesExistingReplaceablePeer, andThrowableDoNotRegisterPreservesReentrantAliasfor three ownership cases.TransferredReferences+TrimmableTypeMapRuntimeCoverage: 78 passed, 0 failed.libMono.Android.NET-Tests.so; it requiresPublishAot=trueandOptimize=truein Debug. The build emitted the expected experimental-runtime and ILC analysis warnings, with 0 errors.Microsoft.NETCore.App.Ref10.0.13 feed package.make preparewithout that workaround had failed with NU1102.CoreCLR (Debug,
RuntimeIdentifier=android-arm64,PublishAot=false,Optimize=false; install/build):NativeAOT (Debug,
RuntimeIdentifier=android-arm64,PublishAot=true,Optimize=true; install/build and test):This demonstrates premature registration and peer-winner displacement, not a permanent GREF leak; no GREF-count test was run.
Refs #13010.title and
description
should follow the
commit-messages.mdworkflow documentation, and in particular should include: