0N/A/*
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @bug 4460983
0N/A * @summary This test verifies that an instance of Activatable cannot
0N/A * be serialized (without implicit impl-to-stub replacement), because
0N/A * it cannot be meaningfully deserialized anyway.
0N/A * See also test/java/rmi/server/RemoteObject/unrecognizedRefType.
0N/A * @author Peter Jones
0N/A *
0N/A * @run main/othervm NotSerializable
0N/A */
0N/A
0N/Aimport java.io.ByteArrayOutputStream;
0N/Aimport java.io.NotSerializableException;
0N/Aimport java.io.ObjectInput;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.ObjectOutput;
0N/Aimport java.lang.reflect.Method;
0N/Aimport java.rmi.MarshalledObject;
0N/Aimport java.rmi.NoSuchObjectException;
0N/Aimport java.rmi.Remote;
0N/Aimport java.rmi.RemoteException;
0N/Aimport java.rmi.server.Operation;
0N/Aimport java.rmi.server.RemoteCall;
0N/Aimport java.rmi.server.RemoteObject;
0N/Aimport java.rmi.server.RemoteRef;
0N/Aimport java.rmi.server.RemoteStub;
0N/Aimport java.rmi.activation.Activatable;
0N/Aimport java.rmi.activation.ActivationID;
0N/Aimport java.rmi.activation.Activator;
0N/A
0N/Apublic class NotSerializable {
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A System.err.println("\nRegression test for bug 4460983\n");
0N/A
0N/A Activatable act = new FakeActivatable();
0N/A try {
0N/A ObjectOutputStream out =
0N/A new ObjectOutputStream(new ByteArrayOutputStream());
0N/A try {
0N/A out.writeObject(act);
0N/A throw new RuntimeException("TEST FAILED: " +
0N/A "Activatable instance successfully serialized");
0N/A } catch (NotSerializableException e) {
0N/A System.err.println("NotSerializableException as expected:");
0N/A e.printStackTrace();
0N/A } // other exceptions cause test failure
0N/A
0N/A System.err.println("TEST PASSED");
0N/A } finally {
0N/A try {
0N/A Activatable.unexportObject(act, true);
0N/A } catch (NoSuchObjectException e) {
0N/A }
0N/A }
0N/A }
0N/A
0N/A private static class FakeActivatable extends Activatable {
0N/A FakeActivatable() throws RemoteException {
0N/A super(new ActivationID(new FakeActivator()), 0);
0N/A }
0N/A }
0N/A
0N/A private static class FakeActivator
0N/A extends RemoteStub implements Activator
0N/A {
0N/A FakeActivator() {
0N/A super(new FakeRemoteRef("FakeRef"));
0N/A }
0N/A
0N/A public MarshalledObject activate(ActivationID id, boolean force) {
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A private static class FakeRemoteRef implements RemoteRef {
0N/A private final String refType;
0N/A
0N/A FakeRemoteRef(String refType) {
0N/A this.refType = refType;
0N/A }
0N/A
0N/A public Object invoke(Remote obj,
0N/A Method method,
0N/A Object[] params,
0N/A long opnum)
0N/A {
0N/A throw new UnsupportedOperationException();
0N/A }
0N/A
0N/A public RemoteCall newCall(RemoteObject obj,
0N/A Operation[] op,
0N/A int opnum,
0N/A long hash)
0N/A {
0N/A throw new UnsupportedOperationException();
0N/A }
0N/A
0N/A public void invoke(RemoteCall call) {
0N/A throw new UnsupportedOperationException();
0N/A }
0N/A
0N/A public void done(RemoteCall call) {
0N/A throw new UnsupportedOperationException();
0N/A }
0N/A
0N/A public String getRefClass(java.io.ObjectOutput out) {
0N/A return refType;
0N/A }
0N/A
0N/A public int remoteHashCode() { return hashCode(); }
0N/A public boolean remoteEquals(RemoteRef obj) { return equals(obj); }
0N/A public String remoteToString() { return toString(); }
0N/A
0N/A public void readExternal(ObjectInput in) {
0N/A throw new UnsupportedOperationException();
0N/A }
0N/A
0N/A public void writeExternal(ObjectOutput out) {
0N/A // no data to write
0N/A }
0N/A }
0N/A}