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 4487532
0N/A * @summary When the system property "sun.rmi.server.suppressStackTraces" is
0N/A * set to boolean true, then the RMI runtime should take positive action to
0N/A * counteract the new feature in 1.4 of an exception's stack trace being part
0N/A * of its serialized form so that the server-side stack trace of an exception
0N/A * that occurs during the execution of a remote method invocation gets
0N/A * marshalled to the client. In most cases, this feature-- along with the
0N/A * final fix to 4010355 to make the server-side stack trace data available
0N/A * at the RMI client application level-- is highly desirable, but this system
0N/A * property provides an opportunity to suppress the server-side stack trace
0N/A * data of exceptions thrown by remote methods from being marshalled, perhaps
0N/A * for reasons of performance or confidentiality requirements.
0N/A * @author Peter Jones
0N/A *
5551N/A * @build SuppressStackTraces Impl2_Stub Impl1_Stub Impl1_Skel
0N/A * @run main/othervm SuppressStackTraces
0N/A */
0N/A
0N/Aimport java.io.IOException;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.rmi.Remote;
0N/Aimport java.rmi.RemoteException;
0N/Aimport java.rmi.server.UnicastRemoteObject;
0N/Aimport java.util.Arrays;
0N/A
0N/Ainterface Pong extends Remote {
0N/A void pong() throws PongException, RemoteException;
0N/A}
0N/A
0N/Aclass PongException extends Exception {
0N/A private void readObject(ObjectInputStream in)
0N/A throws IOException, ClassNotFoundException
0N/A {
0N/A in.defaultReadObject();
0N/A
0N/A /*
0N/A * Verify right at unmarshalling time that this exception instance
0N/A * contains no stack trace data from the server (regardless of whether
0N/A * or not it would be apparent at the RMI client application level).
0N/A */
0N/A StackTraceElement[] trace = getStackTrace();
0N/A if (trace.length > 0) {
0N/A throw new RuntimeException(
0N/A "TEST FAILED: exception contained non-empty stack trace: " +
0N/A Arrays.asList(trace));
0N/A }
0N/A }
0N/A}
0N/A
0N/A // stub class generated with "rmic -v1.2 ..."
0N/Aclass Impl2 implements Pong {
0N/A public void pong() throws PongException { __BAR__(); }
0N/A public void __BAR__() throws PongException { throw new PongException(); }
0N/A}
0N/A
0N/A // stub and skeleton classes generated with "rmic -v1.1 ..."
0N/Aclass Impl1 implements Pong {
0N/A public void pong() throws PongException { __BAR__(); }
0N/A public void __BAR__() throws PongException { throw new PongException(); }
0N/A}
0N/A
0N/Apublic class SuppressStackTraces {
0N/A
0N/A private static void __FOO__(Pong stub)
0N/A throws PongException, RemoteException
0N/A {
0N/A stub.pong();
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 4487532\n");
0N/A
0N/A System.setProperty("sun.rmi.server.suppressStackTraces", "true");
0N/A
0N/A Remote impl2 = new Impl2();
0N/A Remote impl1 = new Impl1();
0N/A
0N/A try {
0N/A /*
0N/A * Verify behavior for both -v1.1 and -v1.2 stub protocols.
0N/A */
0N/A verifySuppression((Pong) UnicastRemoteObject.exportObject(impl2));
0N/A verifySuppression((Pong) UnicastRemoteObject.exportObject(impl1));
0N/A
0N/A System.err.println(
0N/A "TEST PASSED (server-side stack trace data suppressed)");
0N/A } finally {
0N/A try {
0N/A UnicastRemoteObject.unexportObject(impl1, true);
0N/A } catch (Exception e) {
0N/A }
0N/A try {
0N/A UnicastRemoteObject.unexportObject(impl2, true);
0N/A } catch (Exception e) {
0N/A }
0N/A }
0N/A }
0N/A
0N/A private static void verifySuppression(Pong stub) throws Exception {
0N/A System.err.println("testing stub for exported object: " + stub);
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 (PongException 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 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(
0N/A "TEST FAILED: trace contains more than one __FOO__");
0N/A }
0N/A fooIndex = i;
0N/A } else if (e.getMethodName().equals("__BAR__")) {
0N/A throw new RuntimeException(
0N/A "TEST FAILED: trace contains __BAR__");
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 }
0N/A}