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 */
46 */
47
48 import java.lang.reflect.Constructor;
49 import java.lang.reflect.Method;
50 import java.rmi.Remote;
51 import java.rmi.registry.Registry;
52 import java.rmi.registry.LocateRegistry;
53 import java.rmi.server.ObjID;
54 import java.rmi.server.Operation;
55 import java.rmi.server.RemoteCall;
56 import java.rmi.server.RemoteObject;
57 import java.rmi.server.RemoteRef;
58 import java.util.Arrays;
59
60 import sun.rmi.server.UnicastRef;
61 import sun.rmi.transport.LiveRef;
62 import sun.rmi.transport.tcp.TCPEndpoint;
63
64 public class InterfaceHash {
65
66 private static final int PORT = TestLibrary.getUnusedRandomPort();
67 private static final String NAME = "WMM";
68
69 public static void main(String[] args) throws Exception {
70 System.err.println("\nRegression test for bug 4472769");
71
72 System.err.println(
73 "\n=== verifying that J2SE registry's skeleton uses" +
74 "\ncorrect interface hash and operation numbers:");
75
76 Registry testImpl = LocateRegistry.createRegistry(PORT);
77 System.err.println("created test registry on port " + PORT);
78
79 RemoteRef ref = new UnicastRef(
80 new LiveRef(new ObjID(ObjID.REGISTRY_ID),
81 new TCPEndpoint("", PORT), false));
82 Registry referenceStub = new ReferenceRegistryStub(ref);
83 System.err.println("created reference registry stub: " +
84 referenceStub);
85
86 referenceStub.bind(NAME, referenceStub);
87 System.err.println("bound name \"" + NAME + "\" in registry");
88
89 String[] list = referenceStub.list();
90 System.err.println("list of registry contents: " +
91 Arrays.asList(list));
92 if (list.length != 1 || !list[0].equals(NAME)) {
93 throw new RuntimeException(
94 "TEST FAILED: unexpected list contents");
95 }
96
97 Registry result = (Registry) referenceStub.lookup(NAME);
98 System.err.println("lookup of name \"" + NAME + "\" returned: " +
99 result);
100 if (!result.equals(referenceStub)) {
101 throw new RuntimeException(
127 throw new UnsupportedOperationException();
128 }
129 public void invoke(RemoteCall call) { }
130 public void done(RemoteCall call) { }
131 public Object invoke(Remote obj, Method method,
132 Object[] args, long hash)
133 {
134 throw new UnsupportedOperationException();
135 }
136 public String getRefClass(java.io.ObjectOutput out) {
137 return "FakeRemoteRef";
138 }
139 public int remoteHashCode() { return 1013; }
140 public boolean remoteEquals(RemoteRef obj) { return false; }
141 public String remoteToString() { return "FakeRemoteRef"; }
142 public void writeExternal(java.io.ObjectOutput out) { }
143 public void readExternal(java.io.ObjectInput in) { }
144 }
145 FakeRemoteRef f = new FakeRemoteRef();
146
147 Registry testRegistry = LocateRegistry.getRegistry(PORT);
148 System.err.println("created original test registry stub: " +
149 testRegistry);
150
151 Class stubClass = testRegistry.getClass();
152 System.err.println("test registry stub class: " + stubClass);
153
154 Constructor cons = stubClass.getConstructor(
155 new Class[] { RemoteRef.class });
156 Registry testStub = (Registry) cons.newInstance(
157 new Object[] { f });
158 System.err.println("created new instrumented test registry stub: " +
159 testStub);
160
161 System.err.println("invoking bind:");
162 try {
163 testStub.bind(NAME, referenceStub);
164 } catch (UnsupportedOperationException e) {
165 }
166 System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
167 if (f.hash != 4905912898345647071L) {
|
1 /*
2 * Copyright (c) 2001, 2016, 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 */
46 */
47
48 import java.lang.reflect.Constructor;
49 import java.lang.reflect.Method;
50 import java.rmi.Remote;
51 import java.rmi.registry.Registry;
52 import java.rmi.registry.LocateRegistry;
53 import java.rmi.server.ObjID;
54 import java.rmi.server.Operation;
55 import java.rmi.server.RemoteCall;
56 import java.rmi.server.RemoteObject;
57 import java.rmi.server.RemoteRef;
58 import java.util.Arrays;
59
60 import sun.rmi.server.UnicastRef;
61 import sun.rmi.transport.LiveRef;
62 import sun.rmi.transport.tcp.TCPEndpoint;
63
64 public class InterfaceHash {
65
66 private static final String NAME = "WMM";
67
68 public static void main(String[] args) throws Exception {
69 System.err.println("\nRegression test for bug 4472769");
70
71 System.err.println(
72 "\n=== verifying that J2SE registry's skeleton uses" +
73 "\ncorrect interface hash and operation numbers:");
74
75 Registry testImpl = TestLibrary.createRegistryOnEphemeralPort();
76 int regPort = TestLibrary.getRegistryPort(testImpl);
77 System.err.println("created test registry on port " + regPort);
78
79 RemoteRef ref = new UnicastRef(
80 new LiveRef(new ObjID(ObjID.REGISTRY_ID),
81 new TCPEndpoint("", regPort), false));
82 Registry referenceStub = new ReferenceRegistryStub(ref);
83 System.err.println("created reference registry stub: " +
84 referenceStub);
85
86 referenceStub.bind(NAME, referenceStub);
87 System.err.println("bound name \"" + NAME + "\" in registry");
88
89 String[] list = referenceStub.list();
90 System.err.println("list of registry contents: " +
91 Arrays.asList(list));
92 if (list.length != 1 || !list[0].equals(NAME)) {
93 throw new RuntimeException(
94 "TEST FAILED: unexpected list contents");
95 }
96
97 Registry result = (Registry) referenceStub.lookup(NAME);
98 System.err.println("lookup of name \"" + NAME + "\" returned: " +
99 result);
100 if (!result.equals(referenceStub)) {
101 throw new RuntimeException(
127 throw new UnsupportedOperationException();
128 }
129 public void invoke(RemoteCall call) { }
130 public void done(RemoteCall call) { }
131 public Object invoke(Remote obj, Method method,
132 Object[] args, long hash)
133 {
134 throw new UnsupportedOperationException();
135 }
136 public String getRefClass(java.io.ObjectOutput out) {
137 return "FakeRemoteRef";
138 }
139 public int remoteHashCode() { return 1013; }
140 public boolean remoteEquals(RemoteRef obj) { return false; }
141 public String remoteToString() { return "FakeRemoteRef"; }
142 public void writeExternal(java.io.ObjectOutput out) { }
143 public void readExternal(java.io.ObjectInput in) { }
144 }
145 FakeRemoteRef f = new FakeRemoteRef();
146
147 Registry testRegistry = LocateRegistry.getRegistry(regPort);
148 System.err.println("created original test registry stub: " +
149 testRegistry);
150
151 Class stubClass = testRegistry.getClass();
152 System.err.println("test registry stub class: " + stubClass);
153
154 Constructor cons = stubClass.getConstructor(
155 new Class[] { RemoteRef.class });
156 Registry testStub = (Registry) cons.newInstance(
157 new Object[] { f });
158 System.err.println("created new instrumented test registry stub: " +
159 testStub);
160
161 System.err.println("invoking bind:");
162 try {
163 testStub.bind(NAME, referenceStub);
164 } catch (UnsupportedOperationException e) {
165 }
166 System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
167 if (f.hash != 4905912898345647071L) {
|