LoadProxyClasses.java revision 2362
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
*
* @summary functional test for RMIClassLoader.loadProxyClass; test
* ensures that the default RMI class loader provider implements
* RMIClassLoader.loadProxyClass correctly.
*
* @author Laird Dornin
*
* @library ../../../testlibrary
* @build TestLibrary FnnClass FnnUnmarshal LoadProxyClasses NonpublicInterface
* @build NonpublicInterface1 PublicInterface PublicInterface1
*/
/**
* Invokes RMIClassLoader.loadProxyClass() to load a proxy class with
* multiple interfaces using using RMI class unmarshalling. Test is
* composed of cases which each unmarshal a proxy class in a
* different environment. All of the cases create needed class
* loaders, load appropriate interfaces, create a proxy class that
* implements those interfaces, create a marshalled object from that
* proxy class, and finally call .get() on that object. Get of the
* object should pass in some cases and fail in others.
*
* 1. Nonpublic interface loaded from the parent of the First
* Non-Null class Loader on the execution stack (FNNL). Public
* interface loaded from grandparent of FNNL parent. Proxy class must
* be defined in non-null FNNL parent. Should succeed.
*
* 2. Nonpublic interface (java.util.zip.ZipConstants) and public
* interface (java.util.zip.CheckSum) loaded from bootclasspath,
*
* 3. Public interface classes loaded in FNNL are also available in
* RMI loader parent. FNNL is grandparent of RMI loader. Proxy class
* must be defined in RMI class loader. Should succeed. public
* interface must be defined in FNNL.
*
* 4. Non-public interfaces have multiple class loaders. Should fail
* with a LinkageError.
*
* 5. Interface classes loaded from RMI class loader. Proxy class
* defined in RMI class loader.
*
* 6. Not all interfaces classes can be loaded from a single class
* loader; should fail with ClassNotFoundException. All interface
* classes will exist (but not all interfaces will be available from
* one class loader).
*
* 7. prove that proxy loader has correct annotation.
*
* 8. REMIND: may want to add a case where the FNNL is null (This
* would be for class unmarshalling in the implemntation of a remote
* method invocation).
*/
public class LoadProxyClasses {
public static boolean boomerangSemantics = false;
try {
"loads proxy classes correctly\n");
/* install proxy interfaces */
"public");
"public1");
"nonpublic", false);
"nonpublic1", false);
"bothNonpublic");
"bothNonpublic");
/* Case 1 */
new TestInvocationHandler());
/* Case 2 */
new TestInvocationHandler());
/* Case 3 */
new Class[] {publicInterface3},
new TestInvocationHandler());
3, new Case3Checker());
/* Case 4 */
new TestInvocationHandler());
try {
4, null);
} catch (IllegalAccessError e) {
illegal = e;
}
"when multiple nonpublic interfaces have \n" +
"different class loaders");
} else {
"thrown \n when trying to load proxy " +
"with multiple nonpublic interfaces in \n" +
" different class loaders");
}
/* Case 5*/
new Class[] {publicInterface5},
new TestInvocationHandler());
new Case5Checker());
/* Case 6 */
new TestInvocationHandler());
try {
null);
} catch (ClassNotFoundException e) {
cnfe = e;
}
"when not all proxy interfaces could " +
" be found in a single class loader ");
} else {
"correctly thrown when not all proxy" +
" interfaces could be found in a " +
"single class loader");
}
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
TestLibrary.bomb(e);
}
}
private interface LoadChecker {
}
int n,
throws ClassNotFoundException, IOException,
{
} else {
if (unmarshalledLoader != expectedLoader) {
"placed into incorrect loader: " +
} else {
" placed into expected loader: " +
}
}
return proxy;
}
private static class Case3Checker implements LoadChecker {
boolean proxyOk = false;
if (boomerangSemantics) {
if (proxyLoader == ctxLoader) {
proxyOk = true;
}
} else if (proxyLoader.getClass().
{
proxyOk = true;
}
if (proxyOk) {
" correct loader: " + proxyLoader +
proxyLoader).getURLs()));
} else {
"incorrect loader: " + proxyLoader +
proxyLoader).getURLs()));
}
if (ifaceLoader == expectedLoader) {
" correct loader: " + ifaceLoader);
} else {
"incorrect loader: " + ifaceLoader);
}
}
}
private static class Case5Checker implements LoadChecker {
if ((proxyAnnotation == null) ||
{
} else {
}
boolean proxyOk = false;
if (boomerangSemantics) {
if (proxyLoader == ctxLoader) {
proxyOk = true;
}
} else if (proxyLoader.getClass().
{
proxyOk = true;
}
if (proxyOk) {
" correct loader: " + proxyLoader);
} else {
"incorrect loader: " + proxyLoader);
}
}
}
private static class TestInvocationHandler
implements InvocationHandler, Serializable
{
}
}