ResolveProxyClass.java revision 2362
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe/*
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe *
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * This code is free software; you can redistribute it and/or modify it
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * under the terms of the GNU General Public License version 2 only, as
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * published by the Free Software Foundation.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe *
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * This code is distributed in the hope that it will be useful, but WITHOUT
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * version 2 for more details (a copy is included in the LICENSE file that
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * accompanied this code).
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe *
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * You should have received a copy of the GNU General Public License version
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * 2 along with this work; if not, write to the Free Software Foundation,
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe *
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * or visit www.oracle.com if you need additional information or have any
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * questions.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe */
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe/* @test
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * @bug 4258644
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * @summary ObjectInputStream's default implementation of its protected
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * resolveProxyClass method is specified to pass the first non-null class
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * loader up the execution stack to the Proxy.getProxyClass method when
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * it creates the specified proxy class; this test makes sure that it does
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * that in situations where it hadn't in the past, such as if the defining
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * loaders of the interfaces were all strict ancestors of the first
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * non-null loader up the stack.
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * @author Peter Jones
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe *
4edb61f8b0f8ce9f62d803c706612376498672b4al_xipe * @build ResolveProxyClass
* @run main ResolveProxyClass
*/
import java.lang.reflect.*;
import java.io.*;
public class ResolveProxyClass {
/*
* This class is a dummy ObjectInputStream subclass that allows the
* test code to access ObjectInputStream's protected resolveProxyClass
* method directly.
*/
private static class TestObjectInputStream extends ObjectInputStream {
TestObjectInputStream() throws IOException {
super();
}
protected Class resolveProxyClass(String[] interfaces)
throws IOException, ClassNotFoundException
{
return super.resolveProxyClass(interfaces);
}
}
public static void main(String[] args) {
System.err.println("\nRegression test for bug 4258644\n");
try {
/*
* Set this thread's context class loader to null, so that the
* resolveProxyClass implementation cannot cheat by guessing that
* the context class loader is the appropriate loader to pass to
* the Proxy.getProxyClass method.
*/
Thread.currentThread().setContextClassLoader(null);
/*
* Expect the proxy class to be defined in the system class
* loader, because that is the defining loader of this test
* code, and it should be the first loader on the stack when
* ObjectInputStream.resolveProxyClass gets executed.
*/
ClassLoader expectedLoader = ClassLoader.getSystemClassLoader();
TestObjectInputStream in = new TestObjectInputStream();
Class proxyClass = in.resolveProxyClass(
new String[] { Runnable.class.getName() });
ClassLoader proxyLoader = proxyClass.getClassLoader();
System.err.println("proxy class \"" + proxyClass +
"\" defined in loader: " + proxyLoader);
if (proxyLoader != expectedLoader) {
throw new RuntimeException(
"proxy class defined in loader: " + proxyLoader);
}
System.err.println("\nTEST PASSED");
} catch (Throwable e) {
System.err.println("\nTEST FAILED:");
e.printStackTrace();
throw new RuntimeException("TEST FAILED: " + e.toString());
}
}
}