Guard primitive array value-manager routing#12114
Draft
simonrozsival wants to merge 2 commits into
Draft
Conversation
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
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.
Summary
IList<T>handles throughJavaConvertonly when JNI confirms the object implementsjava.util.ListPrimitiveArrayInfopathJniObjectReferenceOptionsbefore all new invalid-cast failuresCheckJNI evidence and safety boundary
The reproducer passed a
java.util.ArrayListhandle while requestingIList<bool>. The reflection value manager selectedJavaBooleanArray.ArrayMarshalerfrom the managed target type alone, leading CheckJNI to abort the process withjarray argument has non-array type: java.util.ArrayList. This change establishes the safety boundary before any array JNI call: only the matching primitive array signature (for example,[Z) may enter that marshaler. A non-array reference may enter collection conversion only when JNIIsInstanceOfconfirmsjava.util.List; other objects and mismatched arrays fail withInvalidCastException. Failure paths dispose and invalidate transferred references according to the requested ownership options.Retained behavior
A genuine Java primitive array still marshals to
IList<T>, and genuine Java List implementations still useJavaConvert. The guard compares the actual JNI runtime type rather than rejectingIList<T>generally.Tests
Added on-device coverage in
JavaConvertTestfor:java.util.ArrayList<Boolean>handle ->IList<bool>boolean[]handle ->IList<bool>Stringhandle ->IList<bool>safely throws, preservingCopyand consumingCopyAndDisposeint[]handle ->IList<bool>safely throws and consumesCopyAndDisposeValidation:
dotnet build external/Java.Interop/src/Java.Interop/Java.Interop.csproj ...passed with 0 warnings/errors after the review fixes.make prepareis required).Mono.Android.csprojbuild reaches the repository prerequisite failure becausebin/BuildDebug/net10.0/xa-prep-tasks.dllis absent.