summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeff Hao <jeffhao@google.com> 2014-04-24 16:06:14 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2014-04-24 16:06:15 +0000
commita062d8d0791967e8c4018be5aeb501b9e7a3460c (patch)
tree38ee752cfcd1a52d37998329fd735d738af8bbe4
parent1768775ec15443a8ff326e63c0b3f8deb17699e6 (diff)
parent63f5b9e8f660ae761901072821ece30d87891644 (diff)
Merge "Add test that Class.newInstance does not wrap its exceptions."
-rw-r--r--test/046-reflect/expected.txt2
-rw-r--r--test/046-reflect/src/Main.java27
2 files changed, 29 insertions, 0 deletions
diff --git a/test/046-reflect/expected.txt b/test/046-reflect/expected.txt
index 55b0dbe8f4..ecb3599482 100644
--- a/test/046-reflect/expected.txt
+++ b/test/046-reflect/expected.txt
@@ -92,6 +92,8 @@ SuperTarget constructor ()V
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 d60fcb485b..3e6d7007f9 100644
--- a/test/046-reflect/src/Main.java
+++ b/test/046-reflect/src/Main.java
@@ -362,6 +362,27 @@ public class Main {
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 @@ class MethodNoisyInitUser {
public static void staticMethod() {}
public void createMethodNoisyInit(MethodNoisyInit ni) {}
}
+
+class Thrower {
+ public Thrower() throws UnsupportedOperationException {
+ throw new UnsupportedOperationException();
+ }
+}