Skip to content

[Unsafe][generator] Prepare safe managed binding contracts - #13104

Merged
simonrozsival merged 5 commits into
simonrozsival-csharp-memory-safetyfrom
simonrozsival-binding-safety-preparation
Oct 19, 2026
Merged

simonrozsival merged 5 commits into
simonrozsival-csharp-memory-safetyfrom
simonrozsival-binding-safety-preparation

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Generated managed bindings historically use member-level unsafe to permit JNI implementation operations. Under updated C# memory-safety rules that becomes a caller contract, making overrides and implementations incompatible with their safe managed base/interface declarations.

Keep those managed declarations safe and move argument storage, JNI invocation, string conversion, array copy-back and owned-reference cleanup into local implementation regions. SourceWriter's body/accessor flags remain independent of IsUnsafe. Preserve JNI signatures, dispatch, callback connectors, cleanup order and both default/direct-UCO callback formats.

Add the None-only deferred Throwable constructor and forwarding path through its generated hierarchy, with no Java-constructor registration or premature peer creation. Raw-handle constructors retain caller obligations. Imported bases use their actual constructor capability; older bases retain legacy initialization, without suppressing unsafe raw-base obligations in updated-mode tests.

This is the binding-preparation layer in the user-selected linear chain #13070 → #13078 → this PR → #13105. Its existing base remains simonrozsival-other-project-memory-safety.

The latest ancestor refresh is a normal merge of exact published tooling tip 7fde6986eb5655dcfd87dd6214a64d9b5a629154, containing validated parent 64bd762488aad1e819a38fbd8840a9c8d97a3d3d and main e03caec36337c9c5698cc60ca3e2ae50839636a5. Merge commit 0b34f3ca17077e8c911bddc3405a7f998a2c4619 has parents 6cd6b0502b946440fa747102d43b57cd8b239537 and that tooling tip.

No rebase, force-push, amend, retarget, direct separate main merge, sibling merge, or stack metadata mutation was performed. The merge had no conflicts. All 121 files and preparation patch hunks relative to the tooling base are unchanged; only Throwable blob IDs changed to reflect inherited main cleanup. Main's removed native/conditional/tooling backends and the canonical outer JNI generator cleanup were preserved.

Product memory-safety activation and its remaining API-contract baselines are separate work; no product/customer feature flag is added. The test compiler's timeout path terminates its owned process tree.

Coverage and API changes

Actual SDK compilation tests exercise C# 9 legacy and updated rules, implementation/reference PE markers, negative raw calls, safe managed overrides/interfaces, both callback formats, reference-field cleanup, string/array marshaling, deferred multilevel constructors and existing peer-constructor hooks. The legacy Roslyn test harness remains covered.

The immediate API baselines add 435 protected constructor signatures for API 37 and 37.1, and 437 for API 37.2. Snapshot changes cover 57 integration files and 24 unit fragments; generated product binding source remains untracked.

Fresh validation after the normal ancestor merge

Validated HEAD: 0b34f3ca17077e8c911bddc3405a7f998a2c4619, exact tooling base 7fde6986eb5655dcfd87dd6214a64d9b5a629154, SDK 12.0.100-alpha.1.26509.101.

  • CONFIGURATION=Debug bash ./eng/install-dotnet.sh — passed, provisioning the new pinned SDK only in this worktree.
  • make prepare CONFIGURATION=Debug — passed.
  • ./dotnet-local.sh build external/Java.Interop/tools/generator/generator.csproj -c Debug -v:q — passed.
  • make leeroy CONFIGURATION=Debug — passed after invalidating only the three owned API generation stamps to force actual canonical regeneration. Includes API 37/37.1/37.2, local workload setup, native/runtime artifacts and API compatibility checks.
  • ./dotnet-local.sh test external/Java.Interop/tests/generator-Tests/generator-Tests.csproj -v:minimal — 485 passed, zero failures/skips, including seven actual new-SDK dual-mode/implementation-reference PE cases.
  • ./dotnet-local.sh test external/Java.Interop/tests/Xamarin.SourceWriter-Tests/Xamarin.SourceWriter-Tests.csproj -v:minimal — 16 passed, zero failures/skips.
  • ./dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll --filter 'FullyQualifiedName~BindDefaultInterfaceMethods|FullyQualifiedName~BindingWithAndroidJavaSource|FullyQualifiedName~BindingCallbackFormatSupportsDefaultConsumer|FullyQualifiedName~UnmanagedCallersOnlyCallbacks|FullyQualifiedName~TrimmableTypeMap_PackagesAndroidJavaProxyThrowable|FullyQualifiedName~TrimmableTypeMap_RuntimeArtifacts|FullyQualifiedName~TrimmableTypeMap_PreserveLists|FullyQualifiedName~AnnotationSupport|FullyQualifiedName~IncrementalBuildTest.ResolveLibraryProjectImports' — 14 passed, zero failed, one existing NativeAOT skip (BindingWithAndroidJavaSource, tracked by #11774).

Freshly regenerated MCW output is byte-for-byte identical to the earlier preparation generation: 6,356 / 6,376 / 6,512 files for API 37/37.1/37.2. Product Features remains empty and LangVersion remains latest.

Historical evidence, not rerun on the new runtime/main base

Before the ancestor refresh, on SDK 12.0.100-alpha.1.26480.102:

  • The full binding/callback/typemap host selector at HEAD 4a9ecb5cc4 passed 245 tests, with one existing NativeAOT skip tracked by #11774.
  • Focused CoreCLR Debug android-arm64 constructor/reference lifecycle tests at that HEAD passed 113 tests on a newly created session-owned API35 AVD. The exact fixture, process, AVD and ini were cleaned up.
  • The actual 120-second timeout probe at test-only HEAD 6cd6b0502b verified termination of an owned blocked host and child, original timeout assertion preservation, and fixture cleanup.

These are retained as historical results only. The new ancestor changes tracked product/runtime/native/test sources and the SDK; unchanged MCW output does not establish new runtime device coverage. No device work or new device lease was used in this ancestor sync.

The prior joint activation host proof also predates this refresh: exact parent d8b67d8c8a, binding HEAD 4a9ecb5cc4 and runtime HEAD 754387a955 had zero memory-safety errors on all three APIs, 14 passing product/companion PE checks and a passing actual new-reference caller graph. API 37 still required 706 RS0016 and 706 RS0017 activation-baseline replacements, verified only through baseline-diagnostic demotion in scratch. That prior result is not claimed to cover the current runtime/main base. Product activation and refreshed combined validation remain separate work.


Pull Request
title and
description
should follow the
commit-messages.md workflow documentation, and in particular should include:

  • Useful description of why the change is necessary.
  • Links to issues fixed — N/A; this is migration preparation, with prerequisite PRs linked above.
  • Unit tests

Copilot AI balanced review requested due to automatic review settings October 13, 2026 08:55

Copilot AI 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.

🔵 Needs a closer look

The broad generator and public API changes retain an unresolved timeout cleanup issue while CI is still running.

1 open finding
What changed in this PR

Prepares generated Android bindings for updated C# memory-safety rules while preserving safe managed contracts and JNI behavior.

Changes:

  • Moves JNI operations into local unsafe implementation scopes.
  • Adds deferred peer construction for Throwable hierarchies.
  • Expands compiler, metadata, lifecycle, and generated-output coverage.
File Description
external/​Java.Interop/​Documentation/​Architecture.md Documents binding safety design.
external/​Java.Interop/​src/​Xamarin.SourceWriter/​Models/​MethodWriter.cs Adds unsafe body scopes.
external/​Java.Interop/​src/​Xamarin.SourceWriter/​Models/​PropertyWriter.cs Adds unsafe accessor scopes.
external/​Java.Interop/​tests/​Xamarin.SourceWriter-Tests/​MethodWriterTests.cs Tests method body scopes.
external/​Java.Interop/​tests/​Xamarin.SourceWriter-Tests/​PropertyWriterTests.cs Tests accessor body scopes.
external/​Java.Interop/​tests/​generator-Tests/​Integration-Tests/​CommandLineCompiler.cs Adds dual-mode compiler harness.
external/​Java.Interop/​tests/​generator-Tests/​Integration-Tests/​Compiler.cs Exposes compiler inputs.
external/​Java.Interop/​tests/​generator-Tests/​Integration-Tests/​NormalMethods.cs Updates generated indentation checks.
external/​Java.Interop/​tests/​generator-Tests/​Integration-Tests/​NormalProperties.cs Updates property output checks.
external/​Java.Interop/​tests/​generator-Tests/​SupportFiles/​JNIEnv.cs Models raw JNI safety contracts.
external/​Java.Interop/​tests/​generator-Tests/​SupportFiles/​JNIEnv.g.cs Updates compile-only JNI stubs.
external/​Java.Interop/​tests/​generator-Tests/​SupportFiles/​JValue.cs Classifies explicit-layout fields.
external/​Java.Interop/​tests/​generator-Tests/​SupportFiles/​JavaObject.cs Adds Throwable constructor stubs.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​BindingMemorySafetyTests.cs Tests contracts and metadata.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1-NRT/​WriteClass.txt Updates NRT class output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1-NRT/​WriteInterface.txt Updates NRT interface output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1-NRT/​WriteMethodWithCharSequenceArrays.txt Updates NRT marshaling output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1-NRT/​WriteObjectField.txt Updates NRT field output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​ObsoleteInterfaceAlternativeClass.txt Updates obsolete interface output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteClass.txt Updates class output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteDefaultInterfaceMethodInvoker.txt Updates DIM invoker output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteDuplicateInterfaceEventArgs.txt Updates event implementor output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteInterface.txt Updates interface output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteInterfaceDefaultMethod.txt Updates DIM output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteInterfaceDefaultProperty.txt Updates DIM property output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteInterfaceDefaultPropertyGetterOnly.txt Updates getter-only DIM output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteInterfaceRedeclaredDefaultMethod.txt Updates redeclared DIM output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteKotlinUnsignedArrayTypeMethodsClass.txt Updates unsigned-array methods.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteKotlinUnsignedArrayTypePropertiesClass.txt Updates unsigned-array properties.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteKotlinUnsignedTypeMethodsClass.txt Updates unsigned methods.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteKotlinUnsignedTypePropertiesClass.txt Updates unsigned properties.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteMethodWithCharSequenceArrays.txt Updates array marshaling output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteNestedInterfaceClass.txt Updates nested invoker output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteNestedInterfaceTypes.txt Updates nested interface output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteObjectField.txt Updates object-field output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteStaticInterfaceMethod.txt Updates static interface method.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteStaticInterfaceProperty.txt Updates static interface property.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorExpectedResults/​XAJavaInterop1/​WriteUnnestedInterfaceTypes.txt Updates unnested invoker output.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​CodeGeneratorTests.cs Updates generator assertions.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​DefaultInterfaceMethodsTests.cs Verifies safe DIM contracts.
external/​Java.Interop/​tests/​generator-Tests/​Unit-Tests/​UnmanagedCallersOnlyCallbackTests.cs Updates callback compilation support.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​AccessModifiers/​Xamarin.Test.BasePublicClass.cs Refreshes generated snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​AccessModifiers/​Xamarin.Test.ExtendPublicClass.cs Refreshes generated snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​AccessModifiers/​Xamarin.Test.IExtendedInterface.cs Refreshes generated snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​AccessModifiers/​Xamarin.Test.PublicClass.cs Refreshes generated snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​AccessModifiers/​Xamarin.Test.PublicFinalClass.cs Refreshes generated snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​AccessModifiers/​Xamarin.Test.TestClass.cs Refreshes generated snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Adapters/​Xamarin.Test.AbsSpinner.cs Refreshes adapter snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Adapters/​Xamarin.Test.AdapterView.cs Refreshes adapter snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Adapters/​Xamarin.Test.GenericReturnObject.cs Refreshes return snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Android.Graphics.Color/​Xamarin.Test.SomeObject.cs Refreshes color snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Arrays/​Xamarin.Test.SomeObject.cs Refreshes array snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​CSharpKeywords/​Java.Lang.Throwable.cs Refreshes Throwable snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​CSharpKeywords/​Xamarin.Test.CSharpKeywords.cs Refreshes keyword snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Constructors/​Xamarin.Test.SomeObject.cs Refreshes constructor snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Constructors/​Xamarin.Test.SomeObject2.cs Refreshes constructor snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Core_Jar2Xml/​Android.Text.ISpannable.cs Refreshes interface snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Core_Jar2Xml/​Android.Text.ISpanned.cs Refreshes interface snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Core_Jar2Xml/​Android.Text.SpannableString.cs Refreshes class snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Core_Jar2Xml/​Android.Text.SpannableStringInternal.cs Refreshes class snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Core_Jar2Xml/​Android.Views.View.cs Refreshes View snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​GenericArguments/​Com.Google.Android.Exoplayer.Drm.FrameworkMediaCrypto.cs Refreshes generic snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​GenericArguments/​Com.Google.Android.Exoplayer.Drm.FrameworkMediaDrm.cs Refreshes generic snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​GenericArguments/​Com.Google.Android.Exoplayer.Drm.IExoMediaCrypto.cs Refreshes generic snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​GenericArguments/​Com.Google.Android.Exoplayer.Drm.IExoMediaDrm.cs Refreshes generic snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​InterfaceMethodsConflict/​Xamarin.Test.II1.cs Refreshes conflict snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​InterfaceMethodsConflict/​Xamarin.Test.II2.cs Refreshes conflict snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​InterfaceMethodsConflict/​Xamarin.Test.SomeObject.cs Refreshes conflict snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​InterfaceMethodsConflict/​Xamarin.Test.SomeObject2.cs Refreshes conflict snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​NestedTypes/​Xamarin.Test.NotificationCompatBase.cs Refreshes nested-type snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​NormalMethods/​Xamarin.Test.A.cs Refreshes method snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​NormalMethods/​Xamarin.Test.C.cs Refreshes method snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​NormalMethods/​Xamarin.Test.SomeObject.cs Refreshes method snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​NormalProperties/​Xamarin.Test.SomeObject.cs Refreshes property snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​ParameterXPath/​Xamarin.Test.A.cs Refreshes XPath snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​StaticMethods/​Xamarin.Test.SomeObject.cs Refreshes static-method snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​StaticProperties/​Xamarin.Test.SomeObject.cs Refreshes static-property snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Streams/​Java.IO.FilterOutputStream.cs Refreshes stream snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Streams/​Java.IO.IOException.cs Adds deferred Throwable path.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Streams/​Java.IO.InputStream.cs Refreshes stream snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Streams/​Java.IO.OutputStream.cs Refreshes stream snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​Streams/​Java.Lang.Throwable.cs Refreshes Throwable snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​TestInterface/​ClassWithoutNamespace.cs Refreshes class snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​TestInterface/​IInterfaceWithoutNamespace.cs Refreshes interface snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​TestInterface/​Java.Util.ICollection.cs Refreshes invoker snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​TestInterface/​Java.Util.IDeque.cs Refreshes invoker snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​TestInterface/​Java.Util.IQueue.cs Refreshes invoker snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​TestInterface/​Test.ME.GenericImplementation.cs Refreshes implementation snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​TestInterface/​Test.ME.GenericObjectPropertyImplementation.cs Refreshes property snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​TestInterface/​Test.ME.GenericStringImplementation.cs Refreshes string snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​TestInterface/​Test.ME.GenericStringPropertyImplementation.cs Refreshes property snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​TestInterface/​Test.ME.IGenericInterface.cs Refreshes generic interface snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​TestInterface/​Test.ME.IGenericPropertyInterface.cs Refreshes generic property snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​TestInterface/​Test.ME.ITestInterface.cs Refreshes interface snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​TestInterface/​Test.ME.TestInterfaceImplementation.cs Refreshes implementation snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​java.lang.Enum/​Java.Lang.Enum.cs Refreshes enum snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​java.lang.Enum/​Java.Lang.IComparable.cs Refreshes invoker snapshot.
external/​Java.Interop/​tests/​generator-Tests/​expected.xaji/​java.util.List/​Xamarin.Test.SomeObject.cs Refreshes list snapshot.
external/​Java.Interop/​tools/​generator/​Java.Interop.Tools.Generator.Importers/​CecilApiImporter.cs Detects deferred base capability.
external/​Java.Interop/​tools/​generator/​Java.Interop.Tools.Generator.ObjectModel/​ClassGen.cs Stores deferred capability.
external/​Java.Interop/​tools/​generator/​SourceWriters/​BoundClass.cs Emits deferred constructors.
external/​Java.Interop/​tools/​generator/​SourceWriters/​BoundConstructor.cs Uses safe deferred initialization.
external/​Java.Interop/​tools/​generator/​SourceWriters/​BoundFieldAsProperty.cs Scopes unsafe field operations.
external/​Java.Interop/​tools/​generator/​SourceWriters/​BoundMethod.cs Scopes unsafe method bodies.
external/​Java.Interop/​tools/​generator/​SourceWriters/​BoundProperty.cs Scopes unsafe accessors.
external/​Java.Interop/​tools/​generator/​SourceWriters/​BoundPropertyStringVariant.cs Scopes string setter operations.
external/​Java.Interop/​tools/​generator/​SourceWriters/​ClassInvokerClass.cs Preserves raw Throwable contracts.
external/​Java.Interop/​tools/​generator/​SourceWriters/​ExplicitInterfaceInvokerMethod.cs Makes interface contracts safe.
external/​Java.Interop/​tools/​generator/​SourceWriters/​Extensions/​SourceWriterExtensions.cs Centralizes safety generation.
external/​Java.Interop/​tools/​generator/​SourceWriters/​InterfaceEventHandlerImplClass.cs Scopes implementor construction.
external/​Java.Interop/​tools/​generator/​SourceWriters/​InterfaceInvokerMethod.cs Makes invoker methods safe.
external/​Java.Interop/​tools/​generator/​SourceWriters/​InterfaceInvokerProperty.cs Makes invoker properties safe.
external/​Java.Interop/​tools/​generator/​SourceWriters/​JavaLangObjectConstructor.cs Marks raw Throwable constructors.
external/​Java.Interop/​tools/​generator/​SourceWriters/​MethodCallback.cs Scopes callback marshaling.
src/​Mono.Android/​Java.Lang/​Throwable.cs Adds empty-peer constructor.
src/​Mono.Android/​PublicAPI/​API-37.1/​PublicAPI.Unshipped.txt Records API 37.1 constructors.
src/​Mono.Android/​PublicAPI/​API-37.2/​PublicAPI.Unshipped.txt Records API 37.2 constructors.
src/​Mono.Android/​PublicAPI/​API-37/​PublicAPI.Unshipped.txt Records API 37 constructors.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​BindingBuildTest.cs Updates binding expectations.
tests/​Mono.Android-Tests/​Mono.Android-Tests/​Java.Interop/​ConstructorActivationTests.cs Categorizes activation coverage.
tests/​Mono.Android-Tests/​Mono.Android-Tests/​System/​ExceptionTest.cs Tests Throwable lifecycle behavior.

🧠 Review effort: Balanced

@simonrozsival
simonrozsival force-pushed the simonrozsival-binding-safety-preparation branch from 4a9ecb5 to e0b2a43 Compare October 13, 2026 09:48
@simonrozsival
simonrozsival changed the base branch from simonrozsival-csharp-memory-safety to simonrozsival-other-project-memory-safety October 13, 2026 09:48
simonrozsival and others added 5 commits October 16, 2026 10:08
Localize JNI argument storage, invocation, marshaling and cleanup without making managed overrides or interface implementations caller-unsafe. Keep caller contracts distinct from SourceWriter body regions and preserve both callback formats.

Add the approved None-only deferred Throwable initialization path throughout the affected inheritance hierarchy, preserving peer-constructor hooks and auditing imported-base capability. Update immediate constructor API baselines and focused dual-mode compiler/PE, snapshot, host and device coverage. Product memory-safety activation remains off.

Co-authored-by: Copilot App <[email protected]>
Remove build-machine SDK/compiler paths from generator test assembly metadata. Compile dual-mode fixtures through the supported dotnet build interface with explicit references and isolated temporary projects, without depending on the SDK Roslyn directory layout.

Co-authored-by: Copilot App <[email protected]>
Keep None-only validation before base initialization in a private static helper, preserving the existing CopyAndDispose result, ArgumentException message/parameter and deferred-peer lifecycle.

Co-authored-by: Copilot App <[email protected]>
Scope setter implementation regions whenever the emitter owns JNI reference cleanup, not only for string fields. Preserve safe property contracts and existing preparation, assignment and finally release order.

Classify fixture DeleteLocalRef as caller-unsafe and exercise instance/static object and object-array fields with actual legacy/updated SDK compilation and implementation/reference PE checks. Regenerate four token-equivalent setter snapshots.

Co-authored-by: Copilot App <[email protected]>
Terminate the owned dotnet host and its descendants before fixture cleanup so timed-out MSBuild/compiler children do not survive the host. Preserve the existing timeout assertion and exit wait.

Co-authored-by: Copilot App <[email protected]>
@simonrozsival
simonrozsival force-pushed the simonrozsival-binding-safety-preparation branch from 0b34f3c to 898022e Compare October 19, 2026 09:56
Base automatically changed from simonrozsival-other-project-memory-safety to simonrozsival-csharp-memory-safety October 19, 2026 10:00
@simonrozsival
simonrozsival merged commit 898022e into main Oct 19, 2026
1 check passed
@simonrozsival
simonrozsival deleted the simonrozsival-binding-safety-preparation branch October 19, 2026 10:00
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants