ResolveProxyClass.java revision 0
0N/A/*
4843N/A * Copyright 1999 Sun Microsystems, Inc. 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
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/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 *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
2362N/A * have any questions.
2362N/A */
2362N/A
0N/A/* @test
0N/A * @bug 4258644
0N/A * @summary ObjectInputStream's default implementation of its protected
0N/A * resolveProxyClass method is specified to pass the first non-null class
0N/A * loader up the execution stack to the Proxy.getProxyClass method when
0N/A * it creates the specified proxy class; this test makes sure that it does
5503N/A * that in situations where it hadn't in the past, such as if the defining
0N/A * loaders of the interfaces were all strict ancestors of the first
0N/A * non-null loader up the stack.
0N/A * @author Peter Jones
0N/A *
0N/A * @build ResolveProxyClass
0N/A * @run main ResolveProxyClass
0N/A */
0N/A
0N/Aimport java.lang.reflect.*;
0N/Aimport java.io.*;
0N/A
0N/Apublic class ResolveProxyClass {
0N/A
0N/A /*
0N/A * This class is a dummy ObjectInputStream subclass that allows the
3471N/A * test code to access ObjectInputStream's protected resolveProxyClass
0N/A * method directly.
0N/A */
0N/A private static class TestObjectInputStream extends ObjectInputStream {
0N/A
0N/A TestObjectInputStream() throws IOException {
0N/A super();
23N/A }
0N/A
5503N/A protected Class resolveProxyClass(String[] interfaces)
5503N/A throws IOException, ClassNotFoundException
5503N/A {
0N/A return super.resolveProxyClass(interfaces);
0N/A }
23N/A }
0N/A
0N/A public static void main(String[] args) {
5182N/A
5182N/A System.err.println("\nRegression test for bug 4258644\n");
5182N/A
5182N/A try {
5182N/A
5182N/A /*
5182N/A * Set this thread's context class loader to null, so that the
5182N/A * resolveProxyClass implementation cannot cheat by guessing that
5182N/A * the context class loader is the appropriate loader to pass to
5182N/A * the Proxy.getProxyClass method.
0N/A */
0N/A Thread.currentThread().setContextClassLoader(null);
0N/A
0N/A /*
0N/A * Expect the proxy class to be defined in the system class
0N/A * loader, because that is the defining loader of this test
0N/A * code, and it should be the first loader on the stack when
0N/A * ObjectInputStream.resolveProxyClass gets executed.
0N/A */
0N/A ClassLoader expectedLoader = ClassLoader.getSystemClassLoader();
0N/A
0N/A TestObjectInputStream in = new TestObjectInputStream();
0N/A Class proxyClass = in.resolveProxyClass(
0N/A new String[] { Runnable.class.getName() });
0N/A ClassLoader proxyLoader = proxyClass.getClassLoader();
0N/A System.err.println("proxy class \"" + proxyClass +
0N/A "\" defined in loader: " + proxyLoader);
0N/A
0N/A if (proxyLoader != expectedLoader) {
0N/A throw new RuntimeException(
0N/A "proxy class defined in loader: " + proxyLoader);
0N/A }
0N/A
0N/A System.err.println("\nTEST PASSED");
0N/A
0N/A } catch (Throwable e) {
0N/A System.err.println("\nTEST FAILED:");
0N/A e.printStackTrace();
0N/A throw new RuntimeException("TEST FAILED: " + e.toString());
0N/A }
0N/A }
0N/A}
0N/A