/*
* 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 8013380
* @summary Remove the stack search for a resource bundle Logger to use
* @author Jim Gish
* @build ResourceBundleSearchTest IndirectlyLoadABundle LoadItUp1 LoadItUp2 TwiceIndirectlyLoadABundle LoadItUp2Invoker
*/
/**
* This class tests various scenarios of loading resource bundles from
* java.util.logging. Since jtreg uses the logging system, it is necessary to
* run these tests using othervm mode to ensure no interference from logging
* initialization by jtreg
*/
public class ResourceBundleSearchTest {
private final static boolean DEBUG = false;
}
// 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
// unless -Djdk.logging.allowStackWalkSearch=true is set
if (allowStackWalkSearch) {
} else {
// default behavior
}
// Test 2 - can we find a Logger bundle off of the Thread context class
// loader? We should be able to.
"2-testGetBundleFromTCCL");
// Test 3 - Can we find a Logger bundle from the classpath? We should be
// able to. We'll first check to make sure the setup is correct and
// it actually is on the classpath before checking whether logging
// can see it there.
"3-testGetBundleFromSystemClassLoader");
} else {
+ " on the classpath");
}
// Test 4 - we should be able to find a bundle from the caller's
// classloader, but only one level up.
"4-testGetBundleFromCallersClassLoader");
// Test 5 - this ensures that getAnonymousLogger(String rbName)
// can find the bundle from the caller's classloader
// Test 6 - first call getLogger("myLogger").
// Then call getLogger("myLogger","bundleName") from a different ClassLoader
// Make sure we find the bundle
if (!allowStackWalkSearch) {
"6-testGetBundleFromSecondCallersClassLoader");
}
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!");
}
}
// This should fail. This was the old functionality to search up the
// caller's call stack
return indirectLoader.loadAndTest();
}
// This should pass. This exercises getting the bundle using the
// class loader of the caller (one level up)
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;
}
}
// 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;
}
// This should pass. This exercises getting the bundle using the
// class loader of the caller (one level up) when calling
// Logger.getAnonymousLogger(String rbName)
return indirectLoader.testGetAnonymousLogger();
}
// This should pass. This exercises getting the bundle using the
// class loader of the caller (one level up)
}
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) {
}
}
}