summaryrefslogtreecommitdiff
path: root/test/200-reflection-errors/src/Main.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/200-reflection-errors/src/Main.java')
-rw-r--r--test/200-reflection-errors/src/Main.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/200-reflection-errors/src/Main.java b/test/200-reflection-errors/src/Main.java
new file mode 100644
index 0000000000..86bbfd4d2b
--- /dev/null
+++ b/test/200-reflection-errors/src/Main.java
@@ -0,0 +1,52 @@
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+public class Main {
+ public static void main(String[] args) throws Exception {
+ // Can't assign Integer to a String field.
+ try {
+ Field field = A.class.getField("b");
+ field.set(new A(), 5);
+ } catch (IllegalArgumentException expected) {
+ System.out.println(expected.getMessage());
+ }
+
+ // Can't unbox null to a primitive.
+ try {
+ Field field = A.class.getField("i");
+ field.set(new A(), null);
+ } catch (IllegalArgumentException expected) {
+ System.out.println(expected.getMessage());
+ }
+
+ // Can't unbox String to a primitive.
+ try {
+ Field field = A.class.getField("i");
+ field.set(new A(), "hello, world!");
+ } catch (IllegalArgumentException expected) {
+ System.out.println(expected.getMessage());
+ }
+
+ // Can't pass an Integer as a String.
+ try {
+ Method m = A.class.getMethod("m", int.class, String.class);
+ m.invoke(new A(), 2, 2);
+ } catch (IllegalArgumentException expected) {
+ System.out.println(expected.getMessage());
+ }
+
+ // Can't pass null as an int.
+ try {
+ Method m = A.class.getMethod("m", int.class, String.class);
+ m.invoke(new A(), null, "");
+ } catch (IllegalArgumentException expected) {
+ System.out.println(expected.getMessage());
+ }
+ }
+}
+
+class A {
+ public String b;
+ public int i;
+ public void m(int i, String s) {}
+}