[typemap] Preserve exported constructor throws metadata - #12564
Open
simonrozsival wants to merge 2 commits into
Open
[typemap] Preserve exported constructor throws metadata#12564simonrozsival wants to merge 2 commits into
simonrozsival wants to merge 2 commits into
Conversation
Carry exported constructor exception metadata through scanning and Java source generation, and add constructor activation coverage for checked exceptions and caller-directed closed generic wrappers. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Convert JNI exception names before checking Java source identifiers so reserved package and nested-type segments are diagnosed for constructors and methods. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs — second is not disposed when Assert.AreSame fails. If GetObject ever… |
What changed in this PR
This PR closes a remaining trimmable typemap parity gap by carrying [Export(... Throws = ...)] exception metadata through scanning and into generated JCW Java constructors (not just methods), while validating/normalizing exception type names for Java source emission. It also adds targeted runtime/integration/unit test coverage for constructor throws propagation and for stable peer identity / exactly-once activation in closed-generic wrapping scenarios.
Changes:
- Propagate
[Export]constructor thrown exception metadata through the trimmable typemap scanner model and into the JCW Java source generator (throwsclauses for constructors). - Normalize/validate thrown exception names via JNI→Java-source conversion before reserved-identifier validation.
- Add/extend runtime, integration, and generator tests to cover constructor
throwsclauses and closed-generic wrapper activation/identity.
| File | Description |
|---|---|
| tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs | Adds runtime coverage for wrapping an existing Java handle as a known closed generic type and ensuring stable peer identity / single activation. |
| tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/ConstructorActivationTests.cs | Adds Java-side activation coverage for an [Export] constructor declaring Throws. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/TestFixtures/TestTypes.cs | Extends fixture types to include an [Export] constructor with declared thrown exception names. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/TestFixtures/StubAttributes.cs | Updates stub Java.Interop.ExportAttribute to support constructors and SuperArgumentsString for scanning/generation tests. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/TrimmableTypeMapGeneratorTests.cs | Updates reserved-name validation coverage to include thrown exception references in constructor/method validation. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator/JcwJavaSourceGeneratorTests.cs | Adds unit coverage asserting generated Java constructors include a throws clause. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/UserTypesFixture/UserTypes.cs | Adds an [Export] constructor with Throws to the integration fixture. |
| tests/Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests/ScannerExportShapesTests.cs | Adds integration assertions that constructor thrown exceptions are surfaced by the scanner model. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/TrimmableTypeMapGenerator.cs | Validates constructor/method thrown exception names after JNI→Java conversion for Java-source identifier checks. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerScanner.cs | Propagates ThrownNames from constructor marshal-methods into JavaConstructorInfo. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerInfo.cs | Extends JavaConstructorInfo model with ThrownNames metadata. |
| src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/JcwJavaSourceGenerator.cs | Emits throws clauses for generated Java constructors and centralizes throws-clause formatting with JNI→Java conversion. |
Comment on lines
+157
to
+162
| using var first = Java.Lang.Object.GetObject<GenericHolder<int>> (handle, JniHandleOwnership.DoNotTransfer); | ||
| var second = Java.Lang.Object.GetObject<GenericHolder<int>> (handle, JniHandleOwnership.DoNotTransfer); | ||
|
|
||
| Assert.IsNotNull (first); | ||
| Assert.AreSame (first, second); | ||
| Assert.AreEqual (1, GenericHolder<int>.ActivationConstructorInvocations); |
This was referenced Aug 28, 2026
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
[Export(Throws = ...)]metadata on generated Java constructorsthrowsclausesTDD matrix
The constructor fixture passed with
llvm-irand failed with the original trimmable typemap because its generated Java constructor omitted the checked exception declaration. After the fix, the unchanged constructor parity category passes under:Additional validation:
Microsoft.Android.Sdk.TrimmableTypeMap.Tests: 771/771Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests: 24/24Fixes #12561