Skip to content

JniType(ReadOnlySpan<byte>) should match JniType(string) lookup semantics #1406

@simonrozsival

Description

@simonrozsival

Summary

JniType(string)/JniEnvironment.Types.FindClass(string) and the UTF-8 ReadOnlySpan<byte> overloads currently do not behave the same.

The string path first tries raw JNI FindClass() and then falls back to Class.forName(name, true, info.Runtime.ClassLoader). The UTF-8 overload only does the raw FindClass() call.

Why this matters

On Android, raw FindClass() can resolve through a different class loader than the runtime/app loader, or fail in cases where Class.forName() succeeds. This means callers using the UTF-8 API can get different behavior and, in some cases, the wrong Class instance.

A portable repro is that the string overload can resolve Java-style names such as "java.lang.Object", while the UTF-8 overload currently throws instead of taking the same fallback path.

Expected behavior

Both overload families should behave identically.

The UTF-8 path should still use raw FindClass() first for the fast path, but if that fails it should marshal to UTF-16 and go through the same Class.forName(..., info.Runtime.ClassLoader) fallback that the string overload uses today.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions