-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0
-
beta
-
sparc
-
solaris_7
-
Verified
Name: abR10010 Date: 08/22/2000
The nsk/logging/Logger/getLogger_ss/getlogr_ss001 test shows
that the Logger.getLogger(logger_name, resource bundle_name)
method for the nonexisting resource bundle runs incorrectly.
The test checks the Logger.getLogger(logger_name, resource_bundle_name)
for the nonexisting resource bundle and catches the expected MissingResourceException
in accordance with the specification.
But the next call of this method with the same logger name and with the
valid resource bundle causes the unexpected IllegalArgumentException
that should be only if the named Logger already exists and has
a different resource bundle.
The call of this method with the other logger name passes.
It means that the first erroneous call of the getLogger() method
creates the new named Logger despite of the MissingResourceException
is thrown.
See logs and test source:
% java getlogr_ss001 -vbs
==> nsk/logging/Logger/getLogger_ss/getlogr_ss001 test LOG:
==> test checks the getLogger(String, String) method of Logger class
of the java.util.logging package
--> getlogr_ss001: check getLogger(s,s) for resource bundle name = null...
--> getlogr_ss001: PASSED: Exception thrown: java.lang.NullPointerException
--> getlogr_ss001: check getLogger(s,s) for nonexisting resource bundle...
--> getlogr_ss001: PASSED: Expected Exception thrown = java.util.MissingResourceException: Can't find bundle for
base name nonexisting_resource_bundle, locale ru_RU
--> getlogr_ss001: check getLogger(s,s) for valid resource bundle...
Exception in thread "main" java.lang.IllegalArgumentException: nonexisting_resource_bundle !=
getlogr_ss001$TestResources
at java.util.logging.Logger.getLogger(Logger.java:234)
at getlogr_ss001.run(getlogr_ss001.java:105)
at getlogr_ss001.main(getlogr_ss001.java:182)
If the next line in the test source
// logger_name = "other_logger_name";
is commented out the test passes:
% java getlogr_ss001 -vbs
==> nsk/logging/Logger/getLogger_ss/getlogr_ss001 test LOG:
==> test checks the getLogger(String, String) method of Logger class
of the java.util.logging package
--> getlogr_ss001: check getLogger(s,s) for resource bundle name = null...
--> getlogr_ss001: PASSED: Exception thrown: java.lang.NullPointerException
--> getlogr_ss001: check getLogger(s,s) for nonexisting resource bundle...
--> getlogr_ss001: PASSED: Expected Exception thrown = java.util.MissingResourceException: Can't find bundle for
base name nonexisting_resource_bundle, locale ru_RU
--> getlogr_ss001: check getLogger(s,s) for valid resource bundle...
--> getlogr_ss001: PASSED: Logger object returned!
--> getlogr_ss001: check name of returned Logger object by logger.getName() method...
--> getlogr_ss001: PASSED: expected name returned - other_logger_name
--> getlogr_ss001: check resource bundle name of returned Logger by logger.getResourceBundleName() method...
--> getlogr_ss001: PASSED: expected resource bundle name returned - getlogr_ss001$TestResources
--> getlogr_ss001: repeated getLogger(s,s) for the same logger name and for the same resource bundle name...
--> getlogr_ss001: PASSED: returned Logger by repeated getLogger(s,s) is the same!
--> getlogr_ss001: all checks for getLogger(s,s) method are PASSED!
==> nsk/logging/Logger/getLogger_ss/getlogr_ss001 test PASSED
The nsk/logging/Logger/getLogger_ss/getlogr_ss001 test sourse:
===============================================================================
// File: %Z%%M% %I% %E%
// Copyright %G% Sun Microsystems, Inc. All Rights Reserved
//package logging.Logger.getLogger_ss;
import java.util.*;
import java.util.logging.*;
public class getlogr_ss001 {
public static class TestResources extends ListResourceBundle {
static final Object[][] contents = {
{"test_resource1_key", "test_resource1"},
{"test_resource2_key", "test_resource2"},
};
public Object[][] getContents() {
return contents;
}
} // end of TestResources class
private final static String
// package_prefix = "logging.Logger.getLogger_ss.";
package_prefix = ""; // for DEBUG without package
static String test_full_name = "logging.Logger.getLogger_ss.getlogr_ss001";
static boolean verbose_mode = false; // test argument -vbs or -verbose switches to true
// - for more easy failure evaluation
static TestResources test_resources_for_compile;
static Logger test_logger;
private static void print_log_on_verbose(String message) {
if ( verbose_mode ) {
System.out.println("--> getlogr_ss001: " + message);
}
}
private static void print_log_without_verbose(String message) {
if ( ! verbose_mode ) {
System.out.println("--> getlogr_ss001: " + message);
}
}
public static int run(String argv[], java.io.PrintStream out) {
int v_test_result = 0/*STATUS_PASSED*/;
int error_check_count = 0;
System.out.println("==> nsk/logging/Logger/getLogger_ss/getlogr_ss001 test LOG:");
System.out.println("==> test checks the getLogger(String, String) method of Logger class");
System.out.println(" of the java.util.logging package\n");
for (int i=0; i<argv.length; i++) {
if ( argv[i].equals("-vbs") || argv[i].equals("-verbose") ) {
verbose_mode = true;
break;
}
}
String logger_name = "logging.Logger.getLogger_ss.getlogr_ss001";
print_log_on_verbose("check getLogger(s,s) for resource bundle name = null...");
String null_resource_bundle_name = null;
try {
test_logger = Logger.getLogger(logger_name, null_resource_bundle_name);
if ( test_logger != null ) {
print_log_without_verbose("check getLogger(s,s) for resource bundle name = null...");
System.out.println("##> getlogr_ss001: Unexpected result - Logger object returned!");
error_check_count++;
}
else {
print_log_on_verbose("PASSED: null returned!");
}
}
catch (Exception e) {
print_log_on_verbose("PASSED: Exception thrown: " + e.toString());
}
print_log_on_verbose("check getLogger(s,s) for nonexisting resource bundle...");
String nonexisting_resource_bundle_name = "nonexisting_resource_bundle";
try {
test_logger = Logger.getLogger(logger_name, nonexisting_resource_bundle_name);
print_log_without_verbose("check getLogger(s,s) for nonexisting resource bundle...");
System.out.println
("##> getlogr_ss001: Unexpected result - MissingResourceException NOT thrown!");
error_check_count++;
}
catch (Throwable e) {
if (e instanceof MissingResourceException) {
print_log_on_verbose("PASSED: Expected Exception thrown = " + e.toString());
}
else {
print_log_without_verbose("check getLogger(s,s) for nonexisting resource bundle...");
System.out.println
("##> getlogr_ss001: Unexpected Exception (NOT MissingResourceException) thrown - "
+ e.toString());
error_check_count++;
}
}
// logger_name = "other_logger_name";
String resource_bundle_name = package_prefix + "getlogr_ss001$TestResources";
while ( true) {
print_log_on_verbose("check getLogger(s,s) for valid resource bundle...");
test_logger = Logger.getLogger(logger_name, resource_bundle_name);
if ( test_logger == null ) {
print_log_without_verbose("check getLogger(s) for valid resource bundle...");
System.out.println("##> getlogr_ss001: Unexpected result - null returned!");
error_check_count++;
break; // there is no sense for further checks
}
else {
print_log_on_verbose("PASSED: Logger object returned!");
}
print_log_on_verbose("check name of returned Logger object by logger.getName() method...");
String got_logger_name = test_logger.getName();
if ( !logger_name.equals(got_logger_name) ) {
print_log_without_verbose
("check name of returned Logger object by logger.getName() method...");
System.out.println("##> getlogr_ss001: returned Unexpected logger name!");
System.out.println("##> expected name = " + logger_name);
System.out.println("##> returned name = " + got_logger_name);
error_check_count++;
}
else {
print_log_on_verbose("PASSED: expected name returned - "
+ logger_name);
}
print_log_on_verbose
("check resource bundle name of returned Logger by logger.getResourceBundleName() method...");
String got_resource_bundle_name = test_logger.getResourceBundleName();
if ( ! resource_bundle_name.equals(got_resource_bundle_name) ) {
print_log_without_verbose
("check resource bundle name of returned Logger by logger.getResourceBundleName() method...");
System.out.println("##> getlogr_ss001: returned Unexpected resource bundle name!");
System.out.println("##> expected name = " + resource_bundle_name);
System.out.println("##> returned name = " + got_resource_bundle_name);
error_check_count++;
}
else {
print_log_on_verbose("PASSED: expected resource bundle name returned - "
+ resource_bundle_name);
}
print_log_on_verbose
("repeated getLogger(s,s) for the same logger name and for the same resource bundle name...");
Logger second_logger = Logger.getLogger(logger_name, resource_bundle_name);
if ( ! test_logger.equals(second_logger) ) {
print_log_without_verbose
("repeated getLogger(s,s) for the same logger name and for the same resource bundle name...");
System.out.println
("##> getlogr_ss001: returned Logger by repeated getLogger(s,s) is NOT the same!");
error_check_count++;
}
else {
print_log_on_verbose("PASSED: returned Logger by repeated getLogger(s,s) is the same!");
}
break;
}
if ( error_check_count != 0 ) {
v_test_result = 2/*STATUS_FAILED*/;
}
else {
System.out.println("--> getlogr_ss001: all checks for getLogger(s,s) method are PASSED!");
}
if ( v_test_result == 2/*STATUS_FAILED*/ ) {
System.out.println("==> nsk/logging/Logger/getLogger_ss/getlogr_ss001 test FAILED");
}
else {
System.out.println("==> nsk/logging/Logger/getLogger_ss/getlogr_ss001 test PASSED");
}
return v_test_result;
}
public static void main(String argv[]) {
System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
}
} // end of getlogr_ss001 class
===============================================================================
======================================================================
- relates to
-
JDK-4378984 logging APIs: getLogger() adds nonexisting resource bundle to named Logger
-
- Closed
-