author | lana |
Thu, 26 Dec 2013 12:04:16 -0800 | |
changeset 23010 | 6dadb192ad81 |
parent 14778 | 5947768d173d |
child 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
14778
diff
changeset
|
2 |
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
25 |
* @bug 4152295 |
|
26 |
* @summary trivial optimization in RemoteProxy.extendsRemote |
|
27 |
* |
|
28 |
* @author Laird Dornin |
|
29 |
* |
|
30 |
* @library ../../testlibrary |
|
14778 | 31 |
* @build TestLibrary |
2 | 32 |
* @run main/othervm GetRemoteClass |
33 |
*/ |
|
34 |
||
35 |
import java.io.Serializable; |
|
36 |
import java.rmi.Remote; |
|
37 |
import sun.rmi.server.Util; |
|
38 |
import 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 |
*/ |
|
47 |
public 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 |
} |