J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 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 4211906 |
| 26 | * @summary If the type of a parameter or return value in an RMI call can be |
| 27 | * successfully downloaded by the receiving endpoint, then an array class with |
| 28 | * that type as its element type should likewise be able to be successfully |
| 29 | * downloaded. This should be true regardless of how many dimensions the |
| 30 | * array has. |
| 31 | * @author Peter Jones |
| 32 | * |
| 33 | * @library ../../../testlibrary |
| 34 | * @build TestLibrary |
| 35 | * @build Receiver |
| 36 | * @build DownloadArrayClass |
| 37 | * @build DownloadArrayClass_Stub |
| 38 | * @build Foo |
| 39 | * @run main/othervm/policy=security.policy DownloadArrayClass |
| 40 | */ |
| 41 | |
| 42 | import java.lang.reflect.Array; |
| 43 | import java.net.*; |
| 44 | import java.rmi.*; |
| 45 | import java.rmi.server.*; |
| 46 | |
| 47 | public class DownloadArrayClass |
| 48 | extends UnicastRemoteObject |
| 49 | implements Receiver |
| 50 | { |
| 51 | |
| 52 | public DownloadArrayClass() throws RemoteException { |
| 53 | } |
| 54 | |
| 55 | public void receive(Object obj) { |
| 56 | System.err.println("+ receive(): received object " + obj); |
| 57 | } |
| 58 | |
| 59 | public static void main(String[] args) { |
| 60 | |
| 61 | System.err.println("\nRegression test for bug 4082868\n"); |
| 62 | |
| 63 | URL remoteCodebase = null; |
| 64 | try { |
| 65 | remoteCodebase = |
| 66 | TestLibrary.installClassInCodebase("Foo", "remote_codebase"); |
| 67 | } catch (MalformedURLException e) { |
| 68 | TestLibrary.bomb(e); |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * Load Foo from a non-RMI class loader so that it won't be already |
| 73 | * loaded by an RMI class loader in this VM (for whatever that's |
| 74 | * worth), but with URLClassLoader so that they will be annotated |
| 75 | * properly. |
| 76 | */ |
| 77 | System.err.println("Creating class loader for remote codebase " + |
| 78 | remoteCodebase); |
| 79 | ClassLoader remoteCodebaseLoader = |
| 80 | URLClassLoader.newInstance(new URL[] { remoteCodebase }); |
| 81 | |
| 82 | TestLibrary.suggestSecurityManager(null); |
| 83 | |
| 84 | System.err.println("Creating remote object."); |
| 85 | DownloadArrayClass obj = null; |
| 86 | try { |
| 87 | obj = new DownloadArrayClass(); |
| 88 | } catch (RemoteException e) { |
| 89 | TestLibrary.bomb(e); |
| 90 | } |
| 91 | |
| 92 | try { |
| 93 | Receiver stub = (Receiver) RemoteObject.toStub(obj); |
| 94 | |
| 95 | /* |
| 96 | * Load the downloadable class "Foo" to marshal over RMI calls |
| 97 | * in various forms. |
| 98 | */ |
| 99 | Class fooClass = remoteCodebaseLoader.loadClass("Foo"); |
| 100 | Object arg; |
| 101 | |
| 102 | /* |
| 103 | * First, to establish that simple class downloading is working |
| 104 | * properly, try marshalling a simple instance of Foo. |
| 105 | */ |
| 106 | arg = fooClass.newInstance(); |
| 107 | System.err.println("Passing object of type " + arg.getClass()); |
| 108 | stub.receive(arg); |
| 109 | |
| 110 | /* |
| 111 | * Second, try marshalling a one-dimensional array of element |
| 112 | * type Foo. |
| 113 | */ |
| 114 | arg = Array.newInstance(fooClass, 26); |
| 115 | System.err.println("Passing object of type " + arg.getClass()); |
| 116 | stub.receive(arg); |
| 117 | |
| 118 | /* |
| 119 | * Finally, try marshalling a multi-dimensional array with |
| 120 | * Foo as the eventual element type. |
| 121 | */ |
| 122 | arg = Array.newInstance(fooClass, new int[] { 1, 42, 0 }); |
| 123 | System.err.println("Passing object of type " + arg.getClass()); |
| 124 | stub.receive(arg); |
| 125 | |
| 126 | System.err.println("TEST PASSED: " + |
| 127 | "arrays of downloaded classes successfully passed"); |
| 128 | |
| 129 | } catch (Exception e) { |
| 130 | System.err.println("TEST FAILED: "); |
| 131 | e.printStackTrace(); |
| 132 | throw new RuntimeException("TEST FAILED: " + e.toString()); |
| 133 | } finally { |
| 134 | try { |
| 135 | UnicastRemoteObject.unexportObject(obj, true); |
| 136 | } catch (Throwable e) { |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |