From 3beb245da9392818e3154d47593f82cf0ef69aac Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Wed, 13 May 2015 13:13:24 -0700 Subject: Also print class for NoSuchFieldException Example message: Caused by: java.lang.NoSuchFieldException: No field value in class Ljava/lang/String; Added test. Bug: 20881251 Change-Id: I4043cbf26c3077952b6c151da0d0edd980da26b1 --- test/046-reflect/src/Main.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'test') 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 @@ public class Main { 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 @@ class OtherClass { System.out.println(e); } } -} \ No newline at end of file +} -- cgit v1.1