blob: bbd9ae0408aec6d2c8716bd3c6312dd2c1957dab [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1999 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/* @test
25 * @bug 4152295
26 * @summary trivial optimization in RemoteProxy.extendsRemote
27 *
28 * @author Laird Dornin
29 *
30 * @library ../../testlibrary
31 * @build GetRemoteClass TestLibrary TestParams
32 * @run main/othervm GetRemoteClass
33 */
34
35import java.io.Serializable;
36import java.rmi.Remote;
37import sun.rmi.server.Util;
38import java.lang.reflect.*;
39
40
41/**
42 * Simple test to make sure that Util.getRemoteClass throws
43 * exception in proper circumstances. Pass two different classes, one
44 * that extends Remote and one that only extends Serializable. Should
45 * throw exception for Serializable.
46 */
47public class GetRemoteClass {
48 public interface ExtendRemote extends Remote {
49 }
50
51 public static class TestRemote implements ExtendRemote {
52 }
53
54 public static class OnlySerializable implements Serializable {
55 }
56
57 public static void main(String[] argv) {
58
59 System.err.println("\nregression test for 4152295\n");
60
61 Method utilGetRemoteClass = null;
62
63 try {
64 /**
65 * Use reflection to set access overrides so that the test
66 * can call protected method, getRemoteClass
67 */
68 Class[] args = new Class[1];
69 args[0] = Class.class;
70 utilGetRemoteClass =
71 Util.class.getDeclaredMethod("getRemoteClass", args);
72 utilGetRemoteClass.setAccessible(true);
73
74 // getRemoteClass can be invoked without exception
75 utilGetRemoteClass.invoke
76 (null , new Object [] {TestRemote.class});
77 System.err.println("remote class flagged as remote");
78
79 ClassNotFoundException cnfe = null;
80 try {
81 // getRemoteClass can be invoked without exception
82 utilGetRemoteClass.invoke
83 (null , new Object [] {OnlySerializable.class});
84 } catch (InvocationTargetException e) {
85 System.err.println("got ClassNotFoundException; remote " +
86 "class flagged as nonremote");
87 cnfe = (ClassNotFoundException) e.getTargetException();
88 }
89 if (cnfe == null) {
90 TestLibrary.bomb("Serializable class flagged as remote?");
91 }
92
93 System.err.println("Test passed.");
94 } catch (Exception e) {
95 TestLibrary.bomb("Unexpected exception", e);
96 }
97 }
98}