ResourceBundleSearchTest.java revision 6330
/*
* 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
* @bug 8010127
* @summary Remove the stack search for a resource bundle Logger to use
* @author Jim Gish
* @build ResourceBundleSearchTest IndirectlyLoadABundle LoadItUp
* @run main ResourceBundleSearchTest
*/
public class ResourceBundleSearchTest {
private final static boolean DEBUG = false;
private static int loggerNum = 0;
private static int numPass = 0;
private static int numFail = 0;
}
// ensure we are using en as the default Locale so we can find the resource
// Find out where we are running from so we can setup the URLClassLoader URL
// Test 1 - can we find a Logger bundle from doing a stack search?
// We shouldn't be able to
// Test 2 - can we find a Logger bundle off of the Thread context class
// loader? We should be able to.
"testGetBundleFromTCCL");
// Test 3 - Can we find a Logger bundle from the classpath? We should be
// able to, but ....
// We check to see if the bundle is on the classpath or not so that this
// the resource bundles are not on the classpath. Running standalone
// (or othervm), they are
"testGetBundleFromSystemClassLoader");
} else {
"testGetBundleFromSystemClassLoader");
}
report();
}
if (numFail > 0) {
// We only care about the messages if they were errors
}
+ " tests failed.");
}
}
if (testResult) {
numPass++;
} else {
numFail++;
+ " was supposed to return true but did NOT!");
}
}
if (!testResult) {
numPass++;
} else {
numFail++;
+ " was supposed to return false but did NOT!");
}
}
public boolean testGetBundleFromStackSearch() throws Throwable {
// This should fail. This was the old functionality to search up the
// caller's call stack
return indirectLoader.loadAndTest();
}
// This should succeed. We should be able to get the bundle from the
// thread context class loader
synchronized (lr) {
try {
} catch (InterruptedException ex) {
throw ex;
}
}
return lr.foundBundle;
}
/*
* @param String bundleClass
* @param ClassLoader to use for search
* @return true iff bundleClass is on system classpath
*/
try {
} catch (MissingResourceException e) {
return false;
}
}
private static String newLoggerName() {
// we need a new logger name every time we attempt to find a bundle via
// the Logger.getLogger call, so we'll simply tack on an integer which
// we increment each time this is called
loggerNum++;
return LOGGER_PREFIX + loggerNum;
}
// this should succeed if the bundle is on the system classpath.
try {
} catch (MissingResourceException re) {
+ bundleName);
return false;
}
+ bundleName);
return true;
}
public static class LoggingThread extends Thread {
boolean foundBundle = false;
this.bundleName = bundleName;
}
this.clToSetOnTCCL = setOnTCCL;
this.bundleName = bundleName;
}
public void run() {
boolean setTCCL = false;
try {
if (clToSetOnTCCL != null) {
setTCCL = true;
}
// this should succeed if the bundle is on the system classpath.
try {
foundBundle = true;
} catch (MissingResourceException re) {
foundBundle = false;
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
if (DEBUG) {
}
}
}