TestBug4179766.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 1.3 99/02/15
@summary test Resource Bundle for bug 4179766
@build Bug4179766Class Bug4179766Resource Bug4179766Getter
@run main TestBug4179766
@bug 4179766
*/
/*
*
*
* (C) Copyright IBM Corp. 1996 - 1999 - All Rights Reserved
*
* Portions copyright (c) 2007 Sun Microsystems, Inc.
* All Rights Reserved.
*
* The original version of this source code and documentation
* is copyrighted and owned by Taligent, Inc., a wholly-owned
* subsidiary of IBM. These materials are provided under terms
* of a License Agreement between Taligent and Sun. This technology
* is protected by multiple US and International patents.
*
* This notice and attribution to Taligent may not be removed.
* Taligent is a registered trademark of Taligent, Inc.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for NON-COMMERCIAL purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies. Please refer to the file "copyright.html"
* for further important copyright and licensing information.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*
*/
/**
* This class tests the behavior of the ResourceBundle cache with
* respect to ClassLoaders. The same resource loaded by different
* loaders should be cached as separate objects, one for each loader.
* In order to test this behavior, this test constructs a custom
* class loader to load its resources. It does not delegate resource
* loading to the system loader to load the class files, but loads
* them from the current directory instead. This is so that the
* defining class loader for the resources is different. If it
* delegated to the system loader to load the resources, the
* defining ClassLoader would be the same even though the initiating
* loader differered, and the resource would only be cached once.
*/
public class TestBug4179766 extends RBTestFmwk {
//hash code used by class loaders when sameHash is true
private static final int SAME_HASH_CODE = 0;
//the next unique hash code
//suffix on class files
//generate a unique hashcode for a class loader
private static synchronized int getNextHashCode() {
return nextHashCode++;
}
//static links so all needed classes get compiled
}
/**
* Ensure the resource cache is working correctly for a single
* resource from a single loader. If we get the same resource
* from the same loader twice, we should get the same resource.
*/
errln("Resource not found: Bug4179766Resource");
}
errln("Resource not found: Bug4179766Resource");
}
errln("Different objects returned by same ClassLoader");
}
}
/**
* Test that loaders with the same hash key still
* cache resources seperately
*/
public void testSameHash() throws Exception {
doTest(true);
}
/**
* Test that loaders with different hash keys
* cache resources seperately
*/
public void testDifferentHash() throws Exception {
doTest(false);
}
/**
* Ensure that cached resources for different ClassLoaders
* are cached seperately
*/
errln("Resource not found: Bug4179766Resource");
}
errln("Resource not found: Bug4179766Resource");
}
errln("Same object returned by different ClassLoaders");
}
}
/**
* Get a resource using a specified class loader to load the resource
*/
try {
} catch (ClassNotFoundException e) {
throw e;
} catch (InstantiationException e) {
throw e;
} catch (IllegalAccessException e) {
throw e;
}
}
/**
* Print information about an object
* [message][object's identity][object's class][object's loader][loaders hash][loaders identity]
*/
if (o == null) {
return;
}
ClassLoader l = c.getClassLoader();
int hash = -1;
if (l != null) {
}
}
/**
* A simple class loader that loads classes from the current
* working directory. The hash code of the loader can be
* set to be either the loaders identity or 0, allowing several
* loaders to have the same hashCode value.
*/
public class Loader extends ClassLoader {
private int thisHashCode;
/**
* Create a new loader
*/
if (sameHash) {
} else {
}
}
/**
* Return the hash code for this loader.
*/
public int hashCode() {
return thisHashCode;
}
/**
* Get the data from the class file for the specified class. If
* the file can't be found, or the class is not one of the
* special ones listed below, return null.
* Bug4179766Class
* Bug4179766Resource
*/
if (shouldLoad) {
try {
return result;
} catch (Exception e) {
return null;
}
} else {
return null;
}
}
/**
* Load a class. Files we can load take preference over ones the system
* can load.
*/
throws ClassNotFoundException {
return result;
}
//we don't have a local copy of this one
return loadFromSystem(className);
}
//there was an error defining the class
return loadFromSystem(className);
}
if (resolveIt) {
}
return result;
}
/**
* Delegate loading to the system loader
*/
try {
return result;
} catch (ClassNotFoundException e) {
throw e;
}
}
/**
* Print information about a class that was loaded
* [loader identity][message][class identity]
*/
if (c != null) {
} else {
}
}
}
}