Skip to content

[JNIEnv] Support sbyte jagged arrays#12115

Draft
simonrozsival wants to merge 2 commits into
mainfrom
dev/simonrozsival/fix-sbyte-jagged-arrays
Draft

[JNIEnv] Support sbyte jagged arrays#12115
simonrozsival wants to merge 2 commits into
mainfrom
dev/simonrozsival/fix-sbyte-jagged-arrays

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Summary

  • add explicit sbyte converters beside the existing byte converters used by shared JNIEnv array creation, copying, reading, and element access
  • reinterpret sbyte[] as JNI byte-array storage bit-for-bit, so negative managed values retain their two's-complement byte representation
  • keep JNI [B fallback routing mapped to managed byte, avoiding any canonicalization of existing byte requests to sbyte

This affects generic and non-generic JNIEnv.NewArray, JNIEnv.GetArray, and JNIEnv.CopyArray paths, including recursive jagged-array handling.

Experiment evidence

Both legacy and trimmable typemap experiments produced the expected JNI signatures ([[B and [[[B) for sbyte jagged arrays. Creation then failed during recursive leaf conversion with:

Don't know how to convert type 'System.SByte' to an Android.Runtime.IJavaObject.

The signatures were therefore already correct; the shared converter dictionaries omitted sbyte while containing byte.

Tests

Added on-device regression coverage for generic and non-generic NewArray/GetArray/CopyArray at ranks 1, 2, and 3:

  • sbyte: minimum, negative, zero, and maximum values
  • byte: values with high bits set, confirming existing unsigned managed behavior remains unchanged
  • JNI signatures asserted as [B, [[B, and [[[B

Validation:

  • dotnet build src/Mono.Android/Mono.Android.csproj --no-restore ... — passed (15 existing warnings)
  • device tests not run because this worktree has no locally built SDK; direct test-project compilation is blocked by missing Java.Interop reflection test types in the unprepared checkout

simonrozsival and others added 2 commits July 15, 2026 11:01
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0e043be9-9070-43bc-aea4-a48438690bdf
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0e043be9-9070-43bc-aea4-a48438690bdf
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.

1 participant