0N/A/*
2362N/A * Copyright (c) 2001, 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 4010355
0N/A * @summary When an exception is thrown by a remote method invocation, the
0N/A * stack trace of the exception catchable by the client application should
0N/A * comprise both the client-side trace as well as the server-side trace, as
0N/A * serialized with the Throwable from the server.
0N/A * @author Peter Jones
0N/A *
5551N/A * @build ServerStackTrace ServerStackTrace_Stub
0N/A * @run main/othervm ServerStackTrace
0N/A */
0N/A
0N/Aimport java.rmi.Remote;
0N/Aimport java.rmi.RemoteException;
0N/Aimport java.rmi.server.UnicastRemoteObject;
0N/A
0N/Ainterface Ping extends Remote {
0N/A void ping() throws PingException, RemoteException;
0N/A}
0N/A
0N/Aclass PingException extends Exception {
0N/A}
0N/A
0N/Apublic class ServerStackTrace implements Ping {
0N/A
0N/A public void ping() throws PingException {
0N/A __BAR__();
0N/A }
0N/A
0N/A private void __BAR__() throws PingException {
0N/A throw new PingException();
0N/A }
0N/A
0N/A private static void __FOO__(Ping stub)
0N/A throws PingException, RemoteException
0N/A {
0N/A stub.ping();
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A
0N/A System.err.println("\nRegression test for RFE 4010355\n");
0N/A
0N/A ServerStackTrace impl = new ServerStackTrace();
0N/A
0N/A try {
0N/A Ping stub = (Ping) UnicastRemoteObject.exportObject(impl);
0N/A
0N/A StackTraceElement[] remoteTrace;
0N/A try {
0N/A __FOO__(stub);
0N/A throw new RuntimeException("TEST FAILED: no exception caught");
0N/A } catch (PingException e) {
0N/A System.err.println(
0N/A "trace of exception thrown by remote call:");
0N/A e.printStackTrace();
0N/A System.err.println();
0N/A remoteTrace = e.getStackTrace();
0N/A }
0N/A
0N/A int fooIndex = -1;
0N/A int barIndex = -1;
0N/A for (int i = 0; i < remoteTrace.length; i++) {
0N/A StackTraceElement e = remoteTrace[i];
0N/A if (e.getMethodName().equals("__FOO__")) {
0N/A if (fooIndex != -1) {
0N/A throw new RuntimeException("TEST FAILED: " +
0N/A "trace contains more than one __FOO__");
0N/A }
0N/A fooIndex = i;
0N/A } else if (e.getMethodName().equals("__BAR__")) {
0N/A if (barIndex != -1) {
0N/A throw new RuntimeException("TEST FAILED: " +
0N/A "trace contains more than one __BAR__");
0N/A }
0N/A barIndex = i;
0N/A }
0N/A }
0N/A if (fooIndex == -1) {
0N/A throw new RuntimeException(
0N/A "TEST FAILED: trace lacks client-side method __FOO__");
0N/A }
0N/A if (barIndex == -1) {
0N/A throw new RuntimeException(
0N/A "TEST FAILED: trace lacks server-side method __BAR__");
0N/A }
0N/A if (fooIndex < barIndex) {
0N/A throw new RuntimeException(
0N/A "TEST FAILED: trace contains client-side method __FOO__ " +
0N/A "before server-side method __BAR__");
0N/A }
0N/A System.err.println("TEST PASSED");
0N/A } finally {
0N/A try {
0N/A UnicastRemoteObject.unexportObject(impl, true);
0N/A } catch (Exception e) {
0N/A }
0N/A }
0N/A }
0N/A}