Also print class for NoSuchFieldException
Example message:
Caused by: java.lang.NoSuchFieldException: No field value in class Ljava/lang/String;
Added test.
(cherry picked from commit 3beb245da9392818e3154d47593f82cf0ef69aac)
Bug: 20881251
Bug: 21027454
Change-Id: I4043cbf26c3077952b6c151da0d0edd980da26b1
diff --git a/test/046-reflect/src/Main.java b/test/046-reflect/src/Main.java
index 59f7001..0d8e576 100644
--- a/test/046-reflect/src/Main.java
+++ b/test/046-reflect/src/Main.java
@@ -233,6 +233,20 @@
field.set(instance, null);
/*
+ * Try getDeclaredField on a non-existant field.
+ */
+ try {
+ field = target.getDeclaredField("nonExistant");
+ System.out.println("ERROR: Expected NoSuchFieldException");
+ } catch (NoSuchFieldException nsfe) {
+ String msg = nsfe.getMessage();
+ if (!msg.contains("Target;")) {
+ System.out.println(" NoSuchFieldException '" + msg +
+ "' didn't contain class");
+ }
+ }
+
+ /*
* Do some stuff with long.
*/
long longVal;
@@ -868,4 +882,4 @@
System.out.println(e);
}
}
-}
\ No newline at end of file
+}