1 /* 2 * Copyright (c) 2005, 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 import java.io.ObjectInput; 25 import java.io.ObjectOutput; 26 import java.lang.reflect.Constructor; 27 import java.lang.reflect.Method; 28 import java.rmi.Remote; 29 import java.rmi.server.Operation; 30 import java.rmi.server.RemoteCall; 31 import java.rmi.server.RemoteObject; 32 import java.rmi.server.RemoteRef; 33 import java.util.Arrays; 34 35 public class Test { main(String[] args)36 public static void main(String[] args) throws Exception { 37 System.err.println("\nRegression test for RFE 5096178\n"); 38 Class<? extends P> cl = 39 Class.forName(PImpl.class.getName() + "_Stub").asSubclass(P.class); 40 Constructor<? extends P> cons = cl.getConstructor(RemoteRef.class); 41 cons.newInstance(new ArgCheckingRemoteRef(Boolean.FALSE)).m(false); 42 cons.newInstance(new ArgCheckingRemoteRef(Boolean.TRUE)).m(true); 43 System.err.println("TEST PASSED"); 44 } 45 printValues(Object... values)46 private static void printValues(Object... values) { 47 System.err.print("{ "); 48 for (int i = 0; i < values.length; i++) { 49 if (i > 0) { 50 System.err.print(", "); 51 } 52 printValue(values[i]); 53 } 54 System.err.println(" }"); 55 } 56 printValue(Object value)57 private static void printValue(Object value) { 58 System.err.print(value.getClass().getName() + "@" + 59 System.identityHashCode(value) + "(" + value + ")"); 60 } 61 62 private static class ArgCheckingRemoteRef extends AbstractRemoteRef { 63 Object[] expected; ArgCheckingRemoteRef(Object... expected)64 ArgCheckingRemoteRef(Object... expected) { 65 this.expected = expected; 66 } test(Object[] args)67 protected void test(Object[] args) { 68 System.err.print("expected argument values: "); 69 printValues(expected); 70 System.err.print(" actual argument values: "); 71 printValues(args); 72 if (args.length != expected.length) { 73 throw new Error("wrong number of arguments"); 74 } 75 for (int i = 0; i < args.length; i++) { 76 if (args[i] != expected[i]) { 77 throw new Error("args[" + i + "] not expected value"); 78 } 79 } 80 } 81 } 82 83 private static abstract class AbstractRemoteRef implements RemoteRef { AbstractRemoteRef()84 AbstractRemoteRef() { } test(Object[] args)85 protected abstract void test(Object[] args); invoke(Remote obj, Method method, Object[] args, long opnum)86 public Object invoke(Remote obj, 87 Method method, 88 Object[] args, 89 long opnum) 90 { 91 test(args); 92 return null; 93 } newCall(RemoteObject obj, Operation[] op, int opnum, long hash)94 public RemoteCall newCall(RemoteObject obj, 95 Operation[] op, 96 int opnum, 97 long hash) 98 { 99 throw new AssertionError(); 100 } invoke(RemoteCall call)101 public void invoke(RemoteCall call) { throw new AssertionError(); } done(RemoteCall call)102 public void done(RemoteCall call) { throw new AssertionError(); } getRefClass(ObjectOutput out)103 public String getRefClass(ObjectOutput out) { 104 throw new AssertionError(); 105 } remoteHashCode()106 public int remoteHashCode() { throw new AssertionError(); } remoteEquals(RemoteRef obj)107 public boolean remoteEquals(RemoteRef obj) { 108 throw new AssertionError(); 109 } remoteToString()110 public String remoteToString() { throw new AssertionError(); } writeExternal(ObjectOutput out)111 public void writeExternal(ObjectOutput out) { 112 throw new AssertionError(); 113 } readExternal(ObjectInput in)114 public void readExternal(ObjectInput in) { 115 throw new AssertionError(); 116 } 117 } 118 } 119