Add test that Class.newInstance does not wrap its exceptions.

Unlike Constructor.newInstance, Class.newInstance should not wrap
exceptions it throws.

Bug: https://code.google.com/p/android/issues/detail?id=68620

Change-Id: I47d78904e72f299284d1382bc715ab120d3b1a7f
diff --git a/test/046-reflect/expected.txt b/test/046-reflect/expected.txt
index 55b0dbe..ecb3599 100644
--- a/test/046-reflect/expected.txt
+++ b/test/046-reflect/expected.txt
@@ -92,6 +92,8 @@
 Target constructor (IF)V : ii=7 ff=3.3333
 myMethod (I)I
  arg=17 anInt=7
+got expected exception for Class.newInstance
+got expected exception for Constructor.newInstance
 ReflectTest done!
 public method
 static java.lang.Object java.util.Collections.checkType(java.lang.Object,java.lang.Class) accessible=false
diff --git a/test/046-reflect/src/Main.java b/test/046-reflect/src/Main.java
index d60fcb4..3e6d700 100644
--- a/test/046-reflect/src/Main.java
+++ b/test/046-reflect/src/Main.java
@@ -362,6 +362,27 @@
             targ = cons.newInstance(args);
             targ.myMethod(17);
 
+            try {
+                Thrower thrower = Thrower.class.newInstance();
+                System.out.println("ERROR: Class.newInstance did not throw exception");
+            } catch (UnsupportedOperationException uoe) {
+                System.out.println("got expected exception for Class.newInstance");
+            } catch (Exception e) {
+                System.out.println("ERROR: Class.newInstance got unexpected exception: " +
+                                   e.getClass().getName());
+            }
+
+            try {
+                Constructor<Thrower> constructor = Thrower.class.getDeclaredConstructor();
+                Thrower thrower = constructor.newInstance();
+                System.out.println("ERROR: Constructor.newInstance did not throw exception");
+            } catch (InvocationTargetException ite) {
+                System.out.println("got expected exception for Constructor.newInstance");
+            } catch (Exception e) {
+                System.out.println("ERROR: Constructor.newInstance got unexpected exception: " +
+                                   e.getClass().getName());
+            }
+
         } catch (Exception ex) {
             System.out.println("----- unexpected exception -----");
             ex.printStackTrace();
@@ -669,3 +690,9 @@
   public static void staticMethod() {}
   public void createMethodNoisyInit(MethodNoisyInit ni) {}
 }
+
+class Thrower {
+  public Thrower() throws UnsupportedOperationException {
+    throw new UnsupportedOperationException();
+  }
+}