Repository navigation
Fix Android NativeAOT JNI string access - #130042
Conversation
Use an ABI-shaped byte* parameter for GetStringUTFChars instead of an out byte byref. This avoids requiring runtime marshalling in NativeAOT test assemblies that disable runtime marshalling. Co-authored-by: Copilot App <[email protected]> Assisted-by: Copilot:gpt-5.5
|
/azp run runtime-android |
|
/azp run runtime-androidemulator |
|
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
There was a problem hiding this comment.
Pull request overview
This PR updates the Android NativeAOT runner template’s JNI interop for GetStringUTFChars to use an ABI-shaped byte* parameter instead of an out byte, avoiding runtime marshalling requirements when [DisableRuntimeMarshalling] is present.
Changes:
- Change the
GetStringUTFCharsfunction-pointer signature fromout bytetobyte*inJNINativeInterface. - Update the call site to pass
&isCopyrather than anoutparameter.
Show a summary per file
| File | Description |
|---|---|
| src/tasks/AndroidAppBuilder/Templates/monodroid-nativeaot.cs | Adjusts the JNI GetStringUTFChars declaration and usage to avoid byref marshalling in NativeAOT runner-generated code. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 1
Remove the Android NativeAOT project exclusions that were tracked by #120725 now that the JNI GetStringUTFChars signature no longer requires byref marshalling. Also initialize the local isCopy byte before passing it to JNI. Co-authored-by: Copilot App <[email protected]> Assisted-by: Copilot:gpt-5.5
This comment has been minimized.
This comment has been minimized.
Resolve the Android NativeAOT test exclusion conflict by keeping this PR's #120725 test re-enable and origin/main's #120959 test re-enable. Co-authored-by: Copilot App <[email protected]> Assisted-by: Copilot:gpt-5.5
989380d to
b733872
Compare
Pass null for the JNI isCopy pointer since the value is unused, and pair every successful GetStringUTFChars call with ReleaseStringUTFChars in a finally block. Co-authored-by: Copilot App <[email protected]> Assisted-by: Copilot:gpt-5.5
This comment has been minimized.
This comment has been minimized.
Copilot Code ReviewHolistic AssessmentMotivation: Well justified. Issue #120725 demonstrates a fatal Approach: Correct and improved. Changing Summary: ✅ LGTM. A well-targeted root cause fix that eliminates the marshalling requirement by matching the JNI C ABI directly. The behavioral improvement (always calling Detailed FindingsDetailed Findings✅ Correctness — Function pointer type matches JNI ABIThe JNI ✅ Resource management — Always-release is correct per JNI specThe old code only called ✅ Caller safety — No use-after-free riskAll callers of ✅ Scope — No other
|
|
/azp run runtime-android |
|
/azp run runtime-androidemulator |
|
Azure Pipelines successfully started running 1 pipeline(s). |
1 similar comment
|
Azure Pipelines successfully started running 1 pipeline(s). |
Fixes #120725. The Android NativeAOT runner template declared `JNIEnv.GetStringUTFChars` with an `out byte` parameter. In test assemblies that include `[DisableRuntimeMarshalling]`, that byref parameter requires runtime marshalling and NativeAOT emits a throwing marshalling thunk before the tests can start. Use the JNI ABI-shaped `byte*` parameter instead and pass the address of the local `isCopy` byte. Validation: - Built `src/tasks/AndroidAppBuilder/AndroidAppBuilder.csproj`. - Re-ran the focused Android NativeAOT `System.Net.Http.Functional.Tests` repro and confirmed the original `CalliMarshallingMethodThunk(... uint8& ...)` crash no longer occurs. > [!NOTE] > This PR description was generated with assistance from GitHub Copilot.
Fixes #120725.
The Android NativeAOT runner template declared
JNIEnv.GetStringUTFCharswith anout byteparameter. In test assemblies that include[DisableRuntimeMarshalling], that byref parameter requires runtime marshalling and NativeAOT emits a throwing marshalling thunk before the tests can start.Use the JNI ABI-shaped
byte*parameter instead and pass the address of the localisCopybyte.Validation:
src/tasks/AndroidAppBuilder/AndroidAppBuilder.csproj.System.Net.Http.Functional.Testsrepro and confirmed the originalCalliMarshallingMethodThunk(... uint8& ...)crash no longer occurs.Note
This PR description was generated with assistance from GitHub Copilot.