Missing (un)boxing for long values in reflection method value marshalling.

This commit is contained in:
Adam J Ryan 2020-01-11 21:07:18 +00:00 committed by Alexey Andreev
parent e064457fe7
commit 42cd4c7cb4
3 changed files with 24 additions and 3 deletions

View File

@ -314,6 +314,9 @@ public class ReflectionDependencyListener extends AbstractDependencyListener {
case INTEGER:
boxMethod = new MethodReference(Integer.class, "valueOf", int.class, Integer.class);
break;
case LONG:
boxMethod = new MethodReference(Long.class, "valueOf", long.class, Long.class);
break;
case FLOAT:
boxMethod = new MethodReference(Float.class, "valueOf", float.class, Float.class);
break;
@ -351,6 +354,9 @@ public class ReflectionDependencyListener extends AbstractDependencyListener {
case INTEGER:
unboxMethod = new MethodReference(Integer.class, "intValue", int.class);
break;
case LONG:
unboxMethod = new MethodReference(Long.class, "longValue", long.class);
break;
case FLOAT:
unboxMethod = new MethodReference(Float.class, "floatValue", float.class);
break;

View File

@ -40,6 +40,7 @@ public class FieldTest {
+ "java.lang.String org.teavm.classlib.java.lang.reflect.FieldTest$ReflectableType.d;"
+ "long org.teavm.classlib.java.lang.reflect.FieldTest$ReflectableType.e;"
+ "private static short org.teavm.classlib.java.lang.reflect.FieldTest$ReflectableType.f;"
+ "long org.teavm.classlib.java.lang.reflect.FieldTest$ReflectableType.g;"
+ "static boolean org.teavm.classlib.java.lang.reflect.FieldTest$ReflectableType.initialized;",
sb.toString());
}
@ -52,6 +53,14 @@ public class FieldTest {
assertEquals(23, result);
}
@Test
public void fieldReadLong() throws NoSuchFieldException, IllegalAccessException {
ReflectableType instance = new ReflectableType();
Field field = instance.getClass().getDeclaredField("g");
Object result = field.get(instance);
assertEquals(Long.MAX_VALUE, result);
}
@Test
public void fieldWritten() throws NoSuchFieldException, IllegalAccessException {
ReflectableType instance = new ReflectableType();
@ -116,10 +125,9 @@ public class FieldTest {
@Reflectable private boolean b;
@Reflectable Object c;
@Reflectable String d;
long e;
@Reflectable private static short f = 99;
@Reflectable long g;
static boolean initialized = true;
@ -129,6 +137,7 @@ public class FieldTest {
c = "foo";
d = "bar";
e = 42;
g = Long.MAX_VALUE;
}
}

View File

@ -36,6 +36,7 @@ public class MethodTest {
assertEquals(""
+ "java.lang.Object Foo.baz();"
+ "public void Foo.accept(long);"
+ "public void Foo.bar(java.lang.Object);",
text);
}
@ -46,7 +47,7 @@ public class MethodTest {
String text = collectMethods(Foo.class.getMethods());
assertEquals("public void Foo.bar(java.lang.Object);", text);
assertEquals("public void Foo.accept(long);public void Foo.bar(java.lang.Object);", text);
}
@Test
@ -94,6 +95,7 @@ public class MethodTest {
private void callMethods() {
new Foo().bar(null);
new Foo().baz();
new Foo().accept(0);
new SuperClass().f();
new SubClass().g();
new SuperClassWithBridge().f();
@ -118,6 +120,10 @@ public class MethodTest {
static class Foo {
Object value;
@Reflectable
public void accept(long l) {
}
@Reflectable
public void bar(Object value) {
this.value = value;