< prev index next >

test/javax/management/remote/mandatory/loading/MethodResultTest.java

Print this page
rev 11832 : 8078896: Add @modules as needed to the jdk_svc tests
Reviewed-by: alanb, mchung

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -24,16 +24,18 @@
 /*
  * @test
  * @bug 4898478
  * @summary Tests client default class loader used before JSR 160 loader
  * @author Eamonn McManus
+ * @modules java.management
  * @run clean MethodResultTest
  * @run build MethodResultTest
  * @run main MethodResultTest
  */
 
 import java.io.*;
+import java.nio.file.Paths;
 import java.net.*;
 import java.util.*;
 import javax.management.*;
 import javax.management.remote.*;
 

@@ -54,28 +56,27 @@
    not be deserialized using the system class loader, which it will be
    with RMI unless special precautions are taken.
  */
 public class MethodResultTest {
     public static void main(String[] args) throws Exception {
-        Class thisClass = MethodResultTest.class;
-        Class exoticClass = Exotic.class;
+        Class<?> thisClass = MethodResultTest.class;
+        Class<?> exoticClass = Exotic.class;
         String exoticClassName = Exotic.class.getName();
-        ClassLoader testClassLoader = thisClass.getClassLoader();
-        if (!(testClassLoader instanceof URLClassLoader)) {
-            System.out.println("TEST INVALID: Not loaded by a " +
-                               "URLClassLoader: " + testClassLoader);
-            System.exit(1);
+
+        String[] cpaths = System.getProperty("test.classes", ".")
+                                .split(File.pathSeparator);
+        URL[] urls = new URL[cpaths.length];
+        for (int i=0; i < cpaths.length; i++) {
+            urls[i] = Paths.get(cpaths[i]).toUri().toURL();
         }
 
-        URLClassLoader tcl = (URLClassLoader) testClassLoader;
-        URL[] urls = tcl.getURLs();
         ClassLoader shadowLoader =
-            new ShadowLoader(urls, testClassLoader,
+            new ShadowLoader(urls, thisClass.getClassLoader(),
                              new String[] {exoticClassName,
                                            ExoticMBeanInfo.class.getName(),
                                            ExoticException.class.getName()});
-        Class cl = shadowLoader.loadClass(exoticClassName);
+        Class<?> cl = shadowLoader.loadClass(exoticClassName);
         if (cl == exoticClass) {
             System.out.println("TEST INVALID: Shadow class loader loaded " +
                                "same class as test class loader");
             System.exit(1);
         }

@@ -195,16 +196,16 @@
     private static Object attrValue(AttributeList attrs) {
         return ((Attribute) attrs.get(0)).getValue();
     }
 
     private static boolean checkType(String what, Object object,
-                                     Class wrongClass) {
+                                     Class<?> wrongClass) {
         return checkType(what, object, wrongClass, false);
     }
 
     private static boolean checkType(String what, Object object,
-                                     Class wrongClass, boolean isException) {
+                                     Class<?> wrongClass, boolean isException) {
         final String type = isException ? "exception" : "object";
         final String rendered = isException ? "thrown" : "returned";
         System.out.println("For " + type + " " + rendered + " by " + what +
                            ":");
         if (wrongClass.isInstance(object)) {

@@ -222,11 +223,11 @@
                            " has same class name but is not same class");
         return true;
     }
 
     private static boolean checkExceptionType(String what, Exception exception,
-                                              Class wrongClass) {
+                                              Class<?> wrongClass) {
         if (!(exception instanceof MBeanException)) {
             System.out.println("Exception thrown by " + what + " is not an " +
                                MBeanException.class.getName() +
                                ":");
             exception.printStackTrace(System.out);

@@ -318,11 +319,11 @@
             super(urls, null);
             this.realLoader = realLoader;
             this.shadowClassNames = Arrays.asList(shadowClassNames);
         }
 
-        protected Class findClass(String name) throws ClassNotFoundException {
+        protected Class<?> findClass(String name) throws ClassNotFoundException {
             if (shadowClassNames.contains(name))
                 return super.findClass(name);
             else
                 return realLoader.loadClass(name);
         }
< prev index next >