Bugfix: Java char is 16 bits, can not be treated as boolean.
Using SetFieldBooleanVolatile() and SetFieldBoolean() happens to work
for char values that only use the lower 8 bits, but is a mistake that
was introduced by the "Add AccessibleObject and Field to mirror" commit:
https://android.googlesource.com/platform/art/+/daaf326
Change-Id: Iec02ba3084c992ea239ecef688d7d29c7e21ae16
diff --git a/runtime/native/java_lang_reflect_Field.cc b/runtime/native/java_lang_reflect_Field.cc
index 01faf3c..5bbb0dc 100644
--- a/runtime/native/java_lang_reflect_Field.cc
+++ b/runtime/native/java_lang_reflect_Field.cc
@@ -253,9 +253,9 @@
break;
case Primitive::kPrimChar:
if (is_volatile) {
- o->SetFieldBooleanVolatile<false>(offset, new_value.GetC());
+ o->SetFieldCharVolatile<false>(offset, new_value.GetC());
} else {
- o->SetFieldBoolean<false>(offset, new_value.GetC());
+ o->SetFieldChar<false>(offset, new_value.GetC());
}
break;
case Primitive::kPrimInt:
diff --git a/test/046-reflect/expected.txt b/test/046-reflect/expected.txt
index fa053fb..d657d44 100644
--- a/test/046-reflect/expected.txt
+++ b/test/046-reflect/expected.txt
@@ -24,7 +24,7 @@
SuperTarget constructor ()V
Target constructor ()V
Before, float is 3.1415925
-myMethod: hi there 3.1415925 Q !
+myMethod: hi there 3.1415925 ✔ !
Result of invoke: 7
Calling no-arg void-return method
myNoargMethod ()V
diff --git a/test/046-reflect/src/Main.java b/test/046-reflect/src/Main.java
index 0d8e576..0c90109 100644
--- a/test/046-reflect/src/Main.java
+++ b/test/046-reflect/src/Main.java
@@ -147,7 +147,7 @@
Object[] argList = new Object[] {
new String[] { "hi there" },
new Float(3.1415926f),
- new Character('Q')
+ new Character('\u2714')
};
System.out.println("Before, float is "
+ ((Float)argList[1]).floatValue());
diff --git a/test/100-reflect2/expected.txt b/test/100-reflect2/expected.txt
index 7db61a1..c932761 100644
--- a/test/100-reflect2/expected.txt
+++ b/test/100-reflect2/expected.txt
@@ -1,6 +1,6 @@
true
8
-x
+✔
3.141592653589793
3.14
32
diff --git a/test/100-reflect2/src/Main.java b/test/100-reflect2/src/Main.java
index 72e14b1..bf3a574 100644
--- a/test/100-reflect2/src/Main.java
+++ b/test/100-reflect2/src/Main.java
@@ -20,7 +20,7 @@
class Main {
private static boolean z = true;
private static byte b = 8;
- private static char c = 'x';
+ private static char c = '\u2714';
private static double d = Math.PI;
private static float f = 3.14f;
private static int i = 32;
@@ -144,7 +144,7 @@
/*
private static boolean z = true;
private static byte b = 8;
- private static char c = 'x';
+ private static char c = '\u2714';
private static double d = Math.PI;
private static float f = 3.14f;
private static int i = 32;
@@ -263,7 +263,7 @@
show(ctor.newInstance((Object[]) null));
ctor = String.class.getConstructor(char[].class, int.class, int.class);
- show(ctor.newInstance(new char[] { 'x', 'y', 'z', '!' }, 1, 2));
+ show(ctor.newInstance(new char[] { '\u2714', 'y', 'z', '!' }, 1, 2));
}
private static void testPackagePrivateConstructor() {