From 2eeb812af8065af81e604b62430817aea3ca106e Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Mon, 23 Mar 2026 18:32:04 +0100 Subject: [PATCH] Fix UTF-8 JNI lookup tests for Android MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- tests/Java.Interop-Tests/Java.Interop/JniTypeUtf8Test.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Java.Interop-Tests/Java.Interop/JniTypeUtf8Test.cs b/tests/Java.Interop-Tests/Java.Interop/JniTypeUtf8Test.cs index b7cc18369..00618c711 100644 --- a/tests/Java.Interop-Tests/Java.Interop/JniTypeUtf8Test.cs +++ b/tests/Java.Interop-Tests/Java.Interop/JniTypeUtf8Test.cs @@ -46,7 +46,11 @@ public void FindClass_Utf8_ReturnsValidReference () [Test] public void FindClass_Utf8_ThrowsOnNotFound () { +#if __ANDROID__ + Assert.Throws (() => JniEnvironment.Types.FindClass ("does/not/Exist"u8)); +#else // __ANDROID__ Assert.Throws (() => JniEnvironment.Types.FindClass ("does/not/Exist"u8)); +#endif // __ANDROID__ } [Test] @@ -172,7 +176,11 @@ public void Dispose_Exceptions_Utf8 () public void InvalidSignature_Utf8_ThrowsJniException () { using (var Object_class = new JniType ("java/lang/Object"u8)) { +#if __ANDROID__ + Assert.Throws (() => Object_class.GetInstanceMethod ("bogus"u8, "(Z)V"u8)); +#else // __ANDROID__ Assert.Throws (() => Object_class.GetInstanceMethod ("bogus"u8, "(Z)V"u8)); +#endif // __ANDROID__ } } }