Skip to content

[Mono.Android] Throw NotSupportedException for open generic type activation#11093

Closed
simonrozsival wants to merge 1 commit intomainfrom
dev/simonrozsival/fix-open-generic-activation
Closed

[Mono.Android] Throw NotSupportedException for open generic type activation#11093
simonrozsival wants to merge 1 commit intomainfrom
dev/simonrozsival/fix-open-generic-activation

Conversation

@simonrozsival
Copy link
Copy Markdown
Member

Adds an IsGenericTypeDefinition guard to JNIEnv.StartCreateInstance(Type, ...) that throws NotSupportedException before attempting to allocate a Java object for an open generic type (e.g., GenericHolder<>).

Background

In the legacy typemap path, open generic types are rejected by ManagedPeer.Construct during FinishCreateInstance:

if (type.IsGenericTypeDefinition)
    throw new NotSupportedException("...");

In the trimmable typemap path, ManagedPeer.Construct is not used — the UCO constructor handles activation. The UCO for open generic types is a no-op (ret), so the activation silently succeeds, which violates the expected behavior.

Fix

Move the check earlier to StartCreateInstance(Type, ...), before AllocObject is called. This ensures consistent behavior regardless of which typemap path is active.

…vation

JNIEnv.StartCreateInstance(Type, ...) now checks type.IsGenericTypeDefinition
and throws NotSupportedException before attempting to allocate the Java object.

In the legacy path, this check was performed later by ManagedPeer.Construct
during FinishCreateInstance. Moving it earlier ensures both the legacy and
trimmable typemap paths fail consistently for open generic types.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot `copilot-cli` or other AIs were used to author this trimmable-type-map

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant