@@ -186,6 +186,13 @@ public void testCallingInvalidMethodRaisesException() throws Throwable {
186186 assertRaisesException ("testController.foo()" );
187187 }
188188
189+ public void testUncaughtJavaExceptionRaisesJavaException () throws Throwable {
190+ injectObjectAndReload (new Object () {
191+ public void method () { throw new RuntimeException ("foo" ); }
192+ }, "testObject" );
193+ assertRaisesException ("testObject.method()" );
194+ }
195+
189196 // Note that this requires that we can pass a JavaScript string to Java.
190197 public void testTypeOfStaticMethod () throws Throwable {
191198 injectObjectAndReload (new ObjectWithStaticMethod (), "testObject" );
@@ -394,7 +401,6 @@ private void privateMethod() {}
394401 assertEquals ("" , mTestController .waitForStringValue ());
395402 }
396403
397- // java.lang.reflect only allows access to public methods and fields. See b/6386557.
398404 public void testReflectPublicMethod () throws Throwable {
399405 injectObjectAndReload (new Object () {
400406 public String method () { return "foo" ; }
@@ -404,12 +410,33 @@ public void testReflectPublicMethod() throws Throwable {
404410 ".toString()" ));
405411 }
406412
407- // java.lang.reflect only allows access to public methods and fields. See b/6386557.
408413 public void testReflectPublicField () throws Throwable {
409414 injectObjectAndReload (new Object () {
410415 public String field = "foo" ;
411416 }, "testObject" );
412417 assertEquals ("foo" , executeJavaScriptAndGetStringResult (
413418 "testObject.getClass().getField('field').get(testObject).toString()" ));
414419 }
420+
421+ public void testReflectPrivateMethodRaisesException () throws Throwable {
422+ injectObjectAndReload (new Object () {
423+ private void method () {};
424+ }, "testObject" );
425+ assertRaisesException ("testObject.getClass().getMethod('method', null)" );
426+ // getDeclaredMethod() is able to access a private method, but invoke()
427+ // throws a Java exception.
428+ assertRaisesException (
429+ "testObject.getClass().getDeclaredMethod('method', null).invoke(testObject, null)" );
430+ }
431+
432+ public void testReflectPrivateFieldRaisesException () throws Throwable {
433+ injectObjectAndReload (new Object () {
434+ private int field ;
435+ }, "testObject" );
436+ assertRaisesException ("testObject.getClass().getField('field')" );
437+ // getDeclaredField() is able to access a private field, but getInt()
438+ // throws a Java exception.
439+ assertRaisesException (
440+ "testObject.getClass().getDeclaredField('field').getInt(testObject)" );
441+ }
415442}
0 commit comments