ART: Fix type parameter in tests
Move Class to Class<?>, Constructor to Constructor<?>, and in
general clean up reflection.
Test: m test-art-host-run-test
Change-Id: I3a4223ee8d14d032015edf34bf27135757f7138c
diff --git a/test/042-new-instance/src/Main.java b/test/042-new-instance/src/Main.java
index 8cd6b2e..755d62e 100644
--- a/test/042-new-instance/src/Main.java
+++ b/test/042-new-instance/src/Main.java
@@ -33,7 +33,7 @@
static void testClassNewInstance() {
// should succeed
try {
- Class c = Class.forName("LocalClass");
+ Class<?> c = Class.forName("LocalClass");
Object obj = c.newInstance();
System.out.println("LocalClass succeeded");
} catch (Exception ex) {
@@ -43,7 +43,7 @@
// should fail
try {
- Class c = Class.forName("otherpackage.PackageAccess");
+ Class<?> c = Class.forName("otherpackage.PackageAccess");
Object obj = c.newInstance();
System.err.println("ERROR: PackageAccess succeeded unexpectedly");
} catch (IllegalAccessException iae) {
@@ -71,8 +71,8 @@
static void testConstructorNewInstance() {
// should fail -- getConstructor only returns public constructors
try {
- Class c = Class.forName("LocalClass");
- Constructor cons = c.getConstructor(new Class[0] /*(Class[])null*/);
+ Class<?> c = Class.forName("LocalClass");
+ Constructor<?> cons = c.getConstructor();
System.err.println("Cons LocalClass succeeded unexpectedly");
} catch (NoSuchMethodException nsme) {
System.out.println("Cons LocalClass failed as expected");
@@ -83,8 +83,8 @@
// should succeed
try {
- Class c = Class.forName("LocalClass2");
- Constructor cons = c.getConstructor((Class[]) null);
+ Class<?> c = Class.forName("LocalClass2");
+ Constructor<?> cons = c.getConstructor();
Object obj = cons.newInstance();
System.out.println("Cons LocalClass2 succeeded");
} catch (Exception ex) {
@@ -94,8 +94,8 @@
// should succeed
try {
- Class c = Class.forName("Main$InnerClass");
- Constructor cons = c.getDeclaredConstructor(new Class<?>[]{Main.class});
+ Class<?> c = Class.forName("Main$InnerClass");
+ Constructor<?> cons = c.getDeclaredConstructor(Main.class);
Object obj = cons.newInstance(new Main());
System.out.println("Cons InnerClass succeeded");
} catch (Exception ex) {
@@ -105,8 +105,8 @@
// should succeed
try {
- Class c = Class.forName("Main$StaticInnerClass");
- Constructor cons = c.getDeclaredConstructor((Class[]) null);
+ Class<?> c = Class.forName("Main$StaticInnerClass");
+ Constructor<?> cons = c.getDeclaredConstructor();
Object obj = cons.newInstance();
System.out.println("Cons StaticInnerClass succeeded");
} catch (Exception ex) {
@@ -116,8 +116,8 @@
// should fail
try {
- Class c = Class.forName("otherpackage.PackageAccess");
- Constructor cons = c.getConstructor(new Class[0] /*(Class[])null*/);
+ Class<?> c = Class.forName("otherpackage.PackageAccess");
+ Constructor<?> cons = c.getConstructor();
System.err.println("ERROR: Cons PackageAccess succeeded unexpectedly");
} catch (NoSuchMethodException nsme) {
// constructor isn't public
@@ -129,8 +129,8 @@
// should fail
try {
- Class c = Class.forName("MaybeAbstract");
- Constructor cons = c.getConstructor(new Class[0] /*(Class[])null*/);
+ Class<?> c = Class.forName("MaybeAbstract");
+ Constructor<?> cons = c.getConstructor();
Object obj = cons.newInstance();
System.err.println("ERROR: Cons MaybeAbstract succeeded unexpectedly");
} catch (InstantiationException ie) {
@@ -143,8 +143,8 @@
// should fail
try {
- Class c = Class.forName("otherpackage.PackageAccess2");
- Constructor cons = c.getConstructor((Class[]) null);
+ Class<?> c = Class.forName("otherpackage.PackageAccess2");
+ Constructor<?> cons = c.getConstructor();
if (!FULL_ACCESS_CHECKS) { throw new IllegalAccessException(); }
Object obj = cons.newInstance();
System.err.println("ERROR: Cons PackageAccess2 succeeded unexpectedly");
@@ -197,7 +197,7 @@
static Object newInstance() {
try {
- Class c = CC.class;
+ Class<?> c = CC.class;
return c.newInstance();
} catch (Exception ex) {
ex.printStackTrace();
diff --git a/test/042-new-instance/src/otherpackage/ConstructorAccess.java b/test/042-new-instance/src/otherpackage/ConstructorAccess.java
index a74e9a0..79d572c 100644
--- a/test/042-new-instance/src/otherpackage/ConstructorAccess.java
+++ b/test/042-new-instance/src/otherpackage/ConstructorAccess.java
@@ -29,8 +29,8 @@
// accessibility using the frame below (in Main class), we will see an
// IllegalAccessException from #newInstance
static public void newConstructorInstance() throws Exception {
- Class c = Inner.class;
- Constructor cons = c.getDeclaredConstructor((Class[]) null);
+ Class<?> c = Inner.class;
+ Constructor cons = c.getDeclaredConstructor();
Object obj = cons.newInstance();
}
}