InvalidProperty.java revision 9330:8b1f1c2a400f
1/*
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/* @test
25 * @bug 4418673
26 * @summary verify that an inavlid setting of the system property
27 * java.rmi.server.RMIClassLoaderSpi causes an Error to be thrown to users
28 * of the RMIClassLoader API.
29 * @author Peter Jones
30 *
31 * @library ../../../testlibrary
32 * @build TestLibrary ServiceConfiguration
33 * @run main/othervm/policy=security.policy InvalidProperty
34 */
35
36import java.rmi.server.RMIClassLoader;
37
38public class InvalidProperty {
39
40    public static void main(String[] args) throws Exception {
41
42        ServiceConfiguration.installServiceConfigurationFile();
43
44        System.setProperty(
45            "java.rmi.server.RMIClassLoaderSpi", "NonexistentProvider");
46
47        String classname = "Foo";
48
49        TestLibrary.suggestSecurityManager(null);
50
51        try {
52            System.err.println("first attempt:");
53            Object ret;
54            try {
55                ret = RMIClassLoader.loadClass(classname);
56            } catch (Exception e) {
57                throw new RuntimeException(
58                    "RMIClassLoader.loadClass threw exception", e);
59            }
60            throw new RuntimeException(
61                "RMIClassLoader.loadClass returned " + ret);
62        } catch (Error e) {
63            System.err.println("RMIClassLoader.loadClass threw an Error:");
64            e.printStackTrace();
65        }
66
67        try {
68            System.err.println("second attempt:");
69            Object ret;
70            try {
71                ret = RMIClassLoader.loadClass(classname);
72            } catch (Exception e) {
73                throw new RuntimeException(
74                    "RMIClassLoader.loadClass threw exception", e);
75            }
76            throw new RuntimeException(
77                "RMIClassLoader.loadClass returned " + ret);
78        } catch (Error e) {
79            System.err.println("RMIClassLoader.loadClass threw an Error:");
80            e.printStackTrace();
81        }
82
83        System.err.println("TEST PASSED");
84    }
85}
86