test/java/lang/reflect/Proxy/ClassRestrictions.java

Print this page

        

@@ -20,19 +20,20 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
 /* @test
- * @bug 4227192
+ * @bug 4227192 8004928
  * @summary This is a test of the restrictions on the parameters that may
  * be passed to the Proxy.getProxyClass method.
  * @author Peter Jones
  *
  * @build ClassRestrictions
  * @run main ClassRestrictions
  */
 
+import java.lang.reflect.Modifier;
 import java.lang.reflect.Proxy;
 import java.net.URLClassLoader;
 
 public class ClassRestrictions {
 

@@ -46,10 +47,12 @@
 
     interface Bashful {
         void foo();
     }
 
+    public static final String nonPublicIntrfaceName = "java.util.zip.ZipConstants";
+    
     public static void main(String[] args) {
 
         System.err.println(
             "\nTest of restrictions on parameters to Proxy.getProxyClass\n");
 

@@ -63,21 +66,21 @@
              * interfaces, not classes or primitive types.
              */
             try {
                 interfaces = new Class<?>[] { Object.class };
                 proxyClass = Proxy.getProxyClass(loader, interfaces);
-                throw new RuntimeException(
+                throw new Error(
                     "proxy class created with java.lang.Object as interface");
             } catch (IllegalArgumentException e) {
                 e.printStackTrace();
                 System.err.println();
                 // assume exception is for intended failure
             }
             try {
                 interfaces = new Class<?>[] { Integer.TYPE };
                 proxyClass = Proxy.getProxyClass(loader, interfaces);
-                throw new RuntimeException(
+                throw new Error(
                     "proxy class created with int.class as interface");
             } catch (IllegalArgumentException e) {
                 e.printStackTrace();
                 System.err.println();
                 // assume exception is for intended failure

@@ -88,11 +91,11 @@
              * Class objects.
              */
             try {
                 interfaces = new Class<?>[] { Bar.class, Bar.class };
                 proxyClass = Proxy.getProxyClass(loader, interfaces);
-                throw new RuntimeException(
+                throw new Error(
                     "proxy class created with repeated interfaces");
             } catch (IllegalArgumentException e) {
                 e.printStackTrace();
                 System.err.println();
                 // assume exception is for intended failure

@@ -107,11 +110,11 @@
             Class altBarClass;
             altBarClass = Class.forName(Bar.class.getName(), false, altLoader);
             try {
                 interfaces = new Class<?>[] { altBarClass };
                 proxyClass = Proxy.getProxyClass(loader, interfaces);
-                throw new RuntimeException(
+                throw new Error(
                     "proxy class created with interface " +
                     "not visible to class loader");
             } catch (IllegalArgumentException e) {
                 e.printStackTrace();
                 System.err.println();

@@ -120,38 +123,20 @@
 
             /*
              * All non-public interfaces must be in the same package.
              */
             Class<?> nonPublic1 = Bashful.class;
-            Class<?> nonPublic2 = null;
-            String[] nonPublicInterfaces = new String[] {
-                "java.awt.Conditional",
-                "java.util.zip.ZipConstants",
-                "javax.swing.GraphicsWrapper",
-                "javax.swing.JPopupMenu$Popup",
-                "javax.swing.JTable$Resizable2",
-                "javax.swing.JTable$Resizable3",
-                "javax.swing.ToolTipManager$Popup",
-                "sun.audio.Format",
-                "sun.audio.HaePlayable",
-                "sun.tools.agent.StepConstants",
-            };
-            for (int i = 0; i < nonPublicInterfaces.length; i++) {
-                try {
-                    nonPublic2 = Class.forName(nonPublicInterfaces[i]);
-                    break;
-                } catch (ClassNotFoundException e) {
-                }
-            }
-            if (nonPublic2 == null) {
-                throw new RuntimeException(
-                    "no second non-public interface found for test");
+            Class<?> nonPublic2 = Class.forName(nonPublicIntrfaceName);
+            if (Modifier.isPublic(nonPublic2.getModifiers())) {
+                throw new Error(
+                    "Interface " + nonPublicIntrfaceName + 
+                    " is public and need to be changed!");
             }
             try {
                 interfaces = new Class<?>[] { nonPublic1, nonPublic2 };
                 proxyClass = Proxy.getProxyClass(loader, interfaces);
-                throw new RuntimeException(
+                throw new Error(
                     "proxy class created with two non-public interfaces " +
                     "in different packages");
             } catch (IllegalArgumentException e) {
                 e.printStackTrace();
                 System.err.println();

@@ -163,11 +148,11 @@
              * parameter signature but different return type.
              */
             try {
                 interfaces = new Class<?>[] { Bar.class, Baz.class };
                 proxyClass = Proxy.getProxyClass(loader, interfaces);
-                throw new RuntimeException(
+                throw new Error(
                     "proxy class created with conflicting methods");
             } catch (IllegalArgumentException e) {
                 e.printStackTrace();
                 System.err.println();
                 // assume exception is for intended failure

@@ -176,12 +161,12 @@
             /*
              * All components of this test have passed.
              */
             System.err.println("\nTEST PASSED");
 
-        } catch (Exception e) {
+        } catch (Throwable e) {
             System.err.println("\nTEST FAILED:");
             e.printStackTrace();
-            throw new RuntimeException("TEST FAILED: " + e.toString());
+            throw new Error("TEST FAILED: ", e);
         }
     }
 }