Index: src/test/api/java/org/apache/harmony/rmi/server/RMIClassLoaderTest.java =================================================================== --- src/test/api/java/org/apache/harmony/rmi/server/RMIClassLoaderTest.java (revision 0) +++ src/test/api/java/org/apache/harmony/rmi/server/RMIClassLoaderTest.java (revision 0) @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.harmony.rmi.server; + +import java.net.URL; +import java.net.URLClassLoader; +import java.rmi.server.RMIClassLoader; +import junit.framework.TestCase; + +public class RMIClassLoaderTest extends TestCase { + /** + * Test for java.rmi.server.RMIclassLoader.loadClass() method + * testing that RMI runtime does not change the order + * of the incoming codebase string (regression test for HARMONY-1944). + */ + public void testLoadClassCodebaseOrder() throws Exception { + if (System.getSecurityManager() == null) { + System.setSecurityManager(new SecurityManager()); + } + URL testJarURL = ClassLoader.getSystemClassLoader().getResource("testClass.jar"); + String[] pathes = new String[] { + testJarURL.getPath(), + "/_fake.jar" // to be sure this path will be the first after sorting + }; + Class c = RMIClassLoader.loadClass("file://" + pathes[0] + " file://" + pathes[1], + "TestClass", null); + ClassLoader cl = c.getClassLoader(); + + if (cl instanceof URLClassLoader) { + URL[] urls = ((URLClassLoader) cl).getURLs(); + + if (urls.length != 2) { + fail("Unexpected number of URLs: " + urls.length); + } + String failStr = ""; + + for (int i = 0; i < urls.length; ++i) { + if (!urls[i].getPath().equals(pathes[i])) { + failStr += "\nURL[" + i + "].getPath() = " + + urls[i].getPath() +", expected: " + pathes[i]; + } + } + + if (!failStr.equals("")) { + fail(failStr); + } + } else { + fail("Class is loaded by non-URLClassLoader"); + } + } +}