Skip to content

Commit dc55197

Browse files
Fix GetFieldID UTF-8 test for Android (#1399)
Integer.value is private and blocked by ART hidden API restrictions, causing NoSuchFieldError on Android. Use StreamTokenizer.ttype instead — a public instance field available on both desktop JVM and Android. Fixes dotnet/android#11005 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent caf0775 commit dc55197

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ public void GetStaticMethodID_Utf8_MatchesStringOverload ()
9090
[Test]
9191
public void GetFieldID_Utf8_MatchesStringOverload ()
9292
{
93-
using (var Integer_class = new JniType ("java/lang/Integer"u8)) {
94-
var fromString = JniEnvironment.InstanceFields.GetFieldID (Integer_class.PeerReference, "value", "I");
95-
var fromUtf8 = JniEnvironment.InstanceFields.GetFieldID (Integer_class.PeerReference, "value"u8, "I"u8);
93+
// Integer.value is private and blocked by ART hidden API restrictions.
94+
// StreamTokenizer.ttype is a public instance field available on both JVM and Android.
95+
using (var StreamTokenizer_class = new JniType ("java/io/StreamTokenizer"u8)) {
96+
var fromString = JniEnvironment.InstanceFields.GetFieldID (StreamTokenizer_class.PeerReference, "ttype", "I");
97+
var fromUtf8 = JniEnvironment.InstanceFields.GetFieldID (StreamTokenizer_class.PeerReference, "ttype"u8, "I"u8);
9698
Assert.AreEqual (fromString.ID, fromUtf8.ID);
9799
}
98100
}

0 commit comments

Comments
 (0)