Add tests for getDeclaredConstructor
Ensure that getDeclaredConstructor throws exceptions for classes,
fields, and methods.
Bug: 16866726
Change-Id: I6f1a1252b9a409dee80653c25ae196db48dc004e
diff --git a/test/046-reflect/src/Main.java b/test/046-reflect/src/Main.java
index 11eb773..3fe3881 100644
--- a/test/046-reflect/src/Main.java
+++ b/test/046-reflect/src/Main.java
@@ -693,10 +693,35 @@
}
}
+ private static void checkGetDeclaredConstructor() {
+ try {
+ Method.class.getDeclaredConstructor().setAccessible(true);
+ System.out.print("Didn't get an exception from method getDeclaredConstructor");
+ } catch (NoSuchMethodException e) {
+ } catch (Exception e) {
+ System.out.print(e);
+ }
+ try {
+ Field.class.getDeclaredConstructor().setAccessible(true);
+ System.out.print("Didn't get an exception from field getDeclaredConstructor");
+ } catch (NoSuchMethodException e) {
+ } catch (Exception e) {
+ System.out.print(e);
+ }
+ try {
+ Class.class.getDeclaredConstructor().setAccessible(true);
+ System.out.print("Didn't get an exception from class getDeclaredConstructor()");
+ } catch (SecurityException e) {
+ } catch (Exception e) {
+ System.out.print(e);
+ }
+ }
+
public static void main(String[] args) throws Exception {
Main test = new Main();
test.run();
+ checkGetDeclaredConstructor();
checkAccess();
checkType();
checkClinitForFields();