Skip to content

[tests] Cover virtual callbacks during construction - #12566

Merged
jonathanpeppers merged 2 commits into
mainfrom
simonrozsival-virtual-constructor-parity
Sep 3, 2026
Merged

[tests] Cover virtual callbacks during construction#12566
jonathanpeppers merged 2 commits into
mainfrom
simonrozsival-virtual-constructor-parity

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Summary

  • add a normal generated-registration fixture whose Java base constructor invokes an overridable managed method
  • cover managed-first and Java-first construction, final peer identity, reentrant and concurrent lookup, exactly-once construction, and callback exception propagation
  • bound concurrency waits so regressions fail deterministically instead of hanging

Matrix

The unchanged fixture passes under llvm-ir/MonoVM, trimmable/CoreCLR, and trimmable/NativeAOT (3/3 each). No production change was required.

Part of #12561

simonrozsivaland others added 2 commits August 28, 2026 13:03
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

Review tier: Lite
Findings: 1 Low severity

New issues introduced by this change (1)
SeverityFinding
Low severitytests/​Mono.Android-Tests/​Mono.Android-Tests/​Java.Interop/​VirtualCallbackConstructorTests.cs — 💡 suggestionjavaClass is declared with using var but never used, which generates CS0219…
What changed in this PR

This PR expands the trimmable typemap runtime coverage test suite by adding a new fixture that validates virtual managed callbacks invoked from Java base constructors during object construction. It targets constructor-time peer identity stability, re-entrant/concurrent lookup behavior, and exception propagation in both managed-first and Java-first activation paths.

Changes:

  • Added a new Java base type whose constructor calls an overridable method to trigger virtual callbacks during construction.
  • Added a new managed test fixture covering managed-first vs Java-first construction, peer identity invariants, bounded concurrency, and callback exception behavior.
  • Wired the new test into the Mono.Android.NET-Tests project compilation list.
FileDescription
tests/​Mono.Android-Tests/​Mono.Android-Tests/​Mono.Android.NET-Tests.csprojIncludes the new virtual-callback constructor parity tests in the on-device test project.
tests/​Mono.Android-Tests/​Mono.Android-Tests/​java/​net/​dot/​android/​test/​VirtualCallbackConstructorBase.javaIntroduces the Java base constructor callback trigger used by the new parity fixture.
tests/​Mono.Android-Tests/​Mono.Android-Tests/​Java.Interop/​VirtualCallbackConstructorTests.csImplements NUnit coverage for constructor-time virtual callbacks, identity invariants, bounded concurrency, and exception propagation.

@simonrozsival

Copy link
Copy Markdown
MemberAuthor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@simonrozsival

Copy link
Copy Markdown
MemberAuthor

/review

@simonrozsivalsimonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Sep 3, 2026
@github-actions

github-actionsBot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12566

@github-actionsgithub-actionsBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: ✅ LGTM

Findings: 0 errors · 0 warnings · 1 suggestion

The fixture exercises the important managed-first and Java-first construction paths, reentrant and concurrent lookup, exactly-once activation, and exception propagation. The bounded waits avoid hanging a device-test lane, and all CI checks are green. I left one non-blocking inline suggestion to clean up unexpected duplicate JNI peers on assertion-failure paths.

Generated by Android PR Reviewer for #12566 · gpt56 · 107.7 AIC · ⌖ 8.88 AIC · ⊞ 25.7K
Comment /review to run again

var registered = Java.Lang.Object.GetObject<VirtualCallbackConstructorDerived> (
instance.Handle,
JniHandleOwnership.DoNotTransfer);
Assert.AreSame (instance, registered);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 💡 JNI references — This assertion deliberately detects a duplicate managed peer, but if GetObject returns a different wrapper, Assert.AreSame exits without disposing that unexpected wrapper and its JNI reference. Please mirror ConstructorActivationTests.AssertRegisteredSame: use a try/finally and dispose registered when it is non-null and not ReferenceEquals(instance, registered). The same failure-path cleanup should cover any distinct wrappers captured in ConcurrentPeers before those references are cleared.

Rule: Dispose unexpected JNI peers

@jonathanpeppers
jonathanpeppers merged commit 71490d5 into mainSep 3, 2026
45 checks passed
@jonathanpeppers
jonathanpeppers deleted the simonrozsival-virtual-constructor-parity branch September 3, 2026 12:46
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-reviewThis PR is ready to review/merge, I think any CI failures are just flaky (ignorable).trimmable-type-map

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@simonrozsival@jonathanpeppers