Repository navigation
[Mono.Android] Type-check JNI callback delegates - #13042
Open
simonrozsival wants to merge 2 commits into
Open
simonrozsival wants to merge 2 commits into
simonrozsival wants to merge 2 commits into
Conversation
Dispatch built-in JNI callbacks by concrete delegate type rather than their simple names. A custom delegate with a colliding name must use the Reflection.Emit fallback with its original delegate type and signature. The 40 built-in mappings and their callback wrappers remain unchanged. Context: #11467 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The focused runtime regression test and SDK build were blocked, leaving the changed JNI callback path unvalidated.
1 open finding
What changed in this PR
Replaces unsafe name-based JNI delegate dispatch with exact runtime-type matching.
Changes:
- Uses typed delegate patterns instead of
Unsafe.As. - Adds regression coverage for same-name custom delegates.
- Keeps generated source synchronized with its T4 template.
| File | Description |
|---|---|
JNINativeWrapper.g.tt |
Updates delegate dispatch generation. |
JNINativeWrapper.g.cs |
Applies generated type-safe mappings. |
JnienvArrayMarshaling.cs |
Adds collision regression test. |
🧠 Review effort: Balanced
| private static Delegate CreateBuiltInDelegate (Delegate dlg, Type delegateType) | ||
| { | ||
| switch (delegateType.Name) { | ||
| switch (dlg) { |
Remove the new CreateDelegate regression test as requested. Its call to CreateDelegate also triggers IL3050 during NativeAOT compilation, even though the test is excluded from NativeAOT execution. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This branch has not been deployed
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
title and
description
should follow the
commit-messages.mdworkflow documentation, and in particular should include:Summary
JNINativeWrapper.CreateBuiltInDelegatedispatches on the runtime delegate type instead of its simple name. Unrelated custom delegates that collide with built-in names therefore use the existing Reflection.Emit fallback with their original delegate type and signature. All 40 built-in mappings and their wrappers remain unchanged. No new tests are included in this PR.Context
#11467 is broader background only; this PR addresses built-in delegate dispatch and does not close that issue.
Validation
cmpverified the generated source matches the template; all 40 mappings remain../dotnet-local.sh test external/Java.Interop/tests/Xamarin.SourceWriter-Tests/Xamarin.SourceWriter-Tests.csproj -v minimal(11 passed)../dotnet-local.sh test external/Java.Interop/tests/generator-Tests/generator-Tests.csproj -v minimal -p:JavaCPath=/Users/simon/Library/Java/JavaVirtualMachines/jdk-23.0.2+7/Contents/Home/bin/javac -p:JarPath=/Users/simon/Library/Java/JavaVirtualMachines/jdk-23.0.2+7/Contents/Home/bin/jar(526 passed).make prepare && make all:make preparefailed during restore with NU1102 becauseMicrosoft.NETCore.App.Ref10.0.13 is unavailable from the configured feeds;make allwas not reached.dotnet-androidchecks for that commit were listed at the time of this update.