Skip to content

Commit caf0775

Browse files
Fix UTF-8 JNI lookup tests for Android (#1398)
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>
1 parent f1722d2 commit caf0775

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

tests/Java.Interop-Tests/Java.Interop/JniTypeUtf8Test.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public void FindClass_Utf8_ReturnsValidReference ()
4646
[Test]
4747
public void FindClass_Utf8_ThrowsOnNotFound ()
4848
{
49+
#if __ANDROID__
50+
Assert.Throws<Java.Lang.ClassNotFoundException> (() => JniEnvironment.Types.FindClass ("does/not/Exist"u8));
51+
#else // __ANDROID__
4952
Assert.Throws<JavaException> (() => JniEnvironment.Types.FindClass ("does/not/Exist"u8));
53+
#endif // __ANDROID__
5054
}
5155

5256
[Test]
@@ -172,7 +176,11 @@ public void Dispose_Exceptions_Utf8 ()
172176
public void InvalidSignature_Utf8_ThrowsJniException ()
173177
{
174178
using (var Object_class = new JniType ("java/lang/Object"u8)) {
179+
#if __ANDROID__
180+
Assert.Throws<Java.Lang.NoSuchMethodError> (() => Object_class.GetInstanceMethod ("bogus"u8, "(Z)V"u8));
181+
#else // __ANDROID__
175182
Assert.Throws<JavaException> (() => Object_class.GetInstanceMethod ("bogus"u8, "(Z)V"u8));
183+
#endif // __ANDROID__
176184
}
177185
}
178186
}

0 commit comments

Comments
 (0)