Skip to content

Fix UTF-8 JNI lookup tests for Android#1398

Merged
jonathanpeppers merged 1 commit intomainfrom
dev/simonrozsival/fix-utf8-tests-android
Mar 23, 2026
Merged

Fix UTF-8 JNI lookup tests for Android#1398
jonathanpeppers merged 1 commit intomainfrom
dev/simonrozsival/fix-utf8-tests-android

Conversation

@simonrozsival
Copy link
Copy Markdown
Member

Summary

The new UTF-8 overload tests from #1393 fail on Android because Assert.Throws<JavaException> expects an exact type match, but the Android runtime throws more specific exception types:

  • FindClassJava.Lang.ClassNotFoundException (not generic JavaException)
  • GetMethodIDJava.Lang.NoSuchMethodError (not generic JavaException)

This happens because the UTF-8 FindClass overload intentionally skips the Class.forName fallback, so the raw JNI exceptions bubble up directly.

Fix

Added #if __ANDROID__ conditionals to expect the Android-specific exception types, matching the existing pattern in JniTypeTest.Ctor_ThrowsIfTypeNotFound and JniTypeTest.InvalidSignatureThrowsJniException.

Fixes dotnet/android#10993

On Android, JNI FindClass throws ClassNotFoundException (not generic
JavaException) and GetMethodID throws NoSuchMethodError. The existing
string-based tests in JniTypeTest.cs already use #if __ANDROID__
conditionals for the same reason — apply the same pattern to the new
UTF-8 overload tests.

Fixes dotnet/android#10993

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates UTF-8 JNI lookup tests to account for Android-specific exception types thrown by the runtime, keeping the new ReadOnlySpan<byte> overload test suite passing across supported platforms.

Changes:

  • Adjust FindClass UTF-8 “not found” test to expect Java.Lang.ClassNotFoundException on Android.
  • Adjust invalid UTF-8 instance method signature test to expect Java.Lang.NoSuchMethodError on Android.

@simonrozsival
Copy link
Copy Markdown
Member Author

/azp run dotnet.java-interop

@azure-pipelines
Copy link
Copy Markdown

No pipelines are associated with this pull request.

@jonathanpeppers jonathanpeppers merged commit caf0775 into main Mar 23, 2026
6 checks passed
@jonathanpeppers jonathanpeppers deleted the dev/simonrozsival/fix-utf8-tests-android branch March 23, 2026 21:20
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 23, 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.

3 participants