summaryrefslogtreecommitdiffstats
path: root/test/201-built-in-exception-detail-messages
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2012-06-19 16:54:19 -0700
committerElliott Hughes <enh@google.com>2012-06-19 16:54:19 -0700
commit6fcce3092040f829afd68862091ce00c7661d8ed (patch)
tree438147684436ab04308a6ff01942a1e78304e778 /test/201-built-in-exception-detail-messages
parent72e401c59bce47fdf0274a0d47f0340b05e4f27f (diff)
downloadart-6fcce3092040f829afd68862091ce00c7661d8ed.tar.gz
art-6fcce3092040f829afd68862091ce00c7661d8ed.tar.bz2
art-6fcce3092040f829afd68862091ce00c7661d8ed.zip
More tests for detail messages, plus a new one.
The array-length instruction is likely to encounter nulls. Change-Id: I628f5f00dfaff9414740e2f7015b9fb3d34a1bc9
Diffstat (limited to 'test/201-built-in-exception-detail-messages')
-rw-r--r--test/201-built-in-exception-detail-messages/src/Main.java103
1 files changed, 103 insertions, 0 deletions
diff --git a/test/201-built-in-exception-detail-messages/src/Main.java b/test/201-built-in-exception-detail-messages/src/Main.java
index 638fb47079..9b67db60fb 100644
--- a/test/201-built-in-exception-detail-messages/src/Main.java
+++ b/test/201-built-in-exception-detail-messages/src/Main.java
@@ -24,6 +24,8 @@ public class Main {
arrayStore();
classCast();
classNotFound();
+ negativeArraySize();
+ nullPointers();
reflection();
stringIndex();
}
@@ -275,6 +277,71 @@ public class Main {
}
}
+ private static void negativeArraySize() throws Exception {
+ try {
+ int[] is = new int[-123];
+ fail();
+ } catch (NegativeArraySizeException ex) {
+ assertEquals("-123", ex.getMessage());
+ }
+ }
+
+ private static void nullPointers() throws Exception {
+ // Invoke method.
+ try {
+ Object o = null;
+ o.hashCode();
+ fail();
+ } catch (NullPointerException ex) {
+ assertEquals("Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference", ex.getMessage());
+ }
+
+ // Read field.
+ try {
+ A a = null;
+ int i = a.i;
+ fail();
+ } catch (NullPointerException ex) {
+ assertEquals("Attempt to read from field 'int A.i' on a null object reference", ex.getMessage());
+ }
+
+ // Write field.
+ try {
+ A a = null;
+ a.i = 1;
+ fail();
+ } catch (NullPointerException ex) {
+ assertEquals("Attempt to write to field 'int A.i' on a null object reference", ex.getMessage());
+ }
+
+ // Read array.
+ try {
+ int[] is = null;
+ int i = is[0];
+ fail();
+ } catch (NullPointerException ex) {
+ assertEquals("Attempt to read from null array", ex.getMessage());
+ }
+
+ // Write array.
+ try {
+ int[] is = null;
+ is[0] = 1;
+ fail();
+ } catch (NullPointerException ex) {
+ assertEquals("Attempt to write to null array", ex.getMessage());
+ }
+
+ // Invoke method.
+ try {
+ int[] is = null;
+ int i = is.length;
+ fail();
+ } catch (NullPointerException ex) {
+ assertEquals("Attempt to get length of null array", ex.getMessage());
+ }
+ }
+
private static void reflection() throws Exception {
// Can't assign Integer to a String field.
try {
@@ -320,6 +387,42 @@ public class Main {
} catch (IllegalArgumentException expected) {
assertEquals("method A.m argument 1 has type int, got null", expected.getMessage());
}
+
+ try {
+ Method m = String.class.getMethod("charAt", int.class);
+ m.invoke("hello"); // Wrong number of arguments.
+ fail();
+ } catch (IllegalArgumentException iae) {
+ assertEquals("wrong number of arguments; expected 1, got 0", iae.getMessage());
+ }
+ try {
+ Method m = String.class.getMethod("charAt", int.class);
+ m.invoke("hello", "world"); // Wrong type.
+ fail();
+ } catch (IllegalArgumentException iae) {
+ assertEquals("method java.lang.String.charAt argument 1 has type int, got java.lang.String", iae.getMessage());
+ }
+ try {
+ Method m = String.class.getMethod("charAt", int.class);
+ m.invoke("hello", (Object) null); // Null for a primitive argument.
+ fail();
+ } catch (IllegalArgumentException iae) {
+ assertEquals("method java.lang.String.charAt argument 1 has type int, got null", iae.getMessage());
+ }
+ try {
+ Method m = String.class.getMethod("charAt", int.class);
+ m.invoke(new Integer(5)); // Wrong type for 'this'.
+ fail();
+ } catch (IllegalArgumentException iae) {
+ assertEquals("expected receiver of type java.lang.String, but got java.lang.Integer", iae.getMessage());
+ }
+ try {
+ Method m = String.class.getMethod("charAt", int.class);
+ m.invoke(null); // Null for 'this'.
+ fail();
+ } catch (NullPointerException npe) {
+ assertEquals("expected receiver of type java.lang.String, but got null", npe.getMessage());
+ }
}
private static void stringIndex() throws Exception {