[tests] Keep GetObjectArray peer alive - #12357
Merged
Merged
Conversation
Capture Application.Context before the JNI array roundtrip so the test verifies identity against a known-live managed peer instead of relying on repeated property access. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an intermittent test failure in JnienvArrayMarshaling.GetObjectArray caused by managed peer identity instability: the test could end up comparing two different managed wrappers for the same Java Context because the wrapper used to populate the JNI object array wasn’t explicitly kept alive (peer registration uses weak references).
Changes:
- Capture
Application.Contextinto a local variable and reuse it when constructing the JNI object array. - Assert round-tripped peer identity against the known-live local
contextinstance instead of a freshApplication.Contextcall.
Member
Author
|
@dalexsoto review |
dalexsoto
approved these changes
Aug 12, 2026
dalexsoto
left a comment
Member
There was a problem hiding this comment.
No blocking issue remains: the test-only lifetime change is harmless on the current runtime path, and the underlying peer-replacement fix is already present.
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.
JnienvArrayMarshaling.GetObjectArrayintermittently compared two managed wrappers for the same Java context because the wrapper inserted into the JNI array was not explicitly retained. Java peer registration uses weak references, so this could fail under CoreCLRTrimmable GC timing even though JNI marshaling returned the correct Java object.Capture
Application.Contextin a local, use that instance to construct the JNI object array, and assert that the roundtrip returns the same known-live managed peer. This preserves the intended peer-identity coverage without requiring a runtime change.adb.