Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4378984

logging APIs: getLogger() adds nonexisting resource bundle to named Logger

XMLWordPrintable

    • beta
    • generic
    • generic
    • Verified



      Name: abR10010 Date: 10/12/2000



      The nsk/logging/Logger/getLogger_ss/getlogr_ss002 test shows
      that the Logger.getLogger(logger_name, resource_bundle_name)
      method for the nonexisting resource bundle runs incorrectly
      for case when the named Logger already exists and does not yet
      have a localization resource bundle.

      MissingResourceException is thrown but nonexisting
      resource bundle is added to the existing named Logger:
      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.

      This failure happens under the HotSpot Client VM (build 1.4beta-B35).

      NOTES.
         The bug like this (Bug Id: 4364959) had been filed for case when
         the getLogger(...) method creates a new named Logger with nonexisting resource bundle.
         According to the current state of bugreport this bug had been fixed and
         integrated in merlin-beta release on Sep 28 2000.



      See log and test source:

      % java -version
      java version "1.4.0beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0beta-b35)
      Java HotSpot(TM) Client VM (build 1.4beta-B35, mixed mode)


      % java getlogr_ss002 -vbs
      ==> nsk/logging/Logger/getLogger_ss/getlogr_ss002 test LOG:
      ==> test checks the getLogger(String, String) method of Logger class
          of the java.util.logging package for case when the named Logger
          already exists and does not yet have a localization resource bundle

      --> getlogr_ss002: check getLogger(String, String) for existing named Logger and nonexisting resource
      bundle...
      --> getlogr_ss002: PASSED: Expected Exception thrown = java.util.MissingResourceException: Can't find
      bundle for base name nonexisting_resource_bundle, locale ru_RU
      --> getlogr_ss002: check getLogger(String, String) for existing named Logger and valid resource bundle...
      Exception in thread "main" java.lang.IllegalArgumentException: nonexisting_resource_bundle !=
      getlogr_ss002$TestResources
      at java.util.logging.Logger.getLogger(Logger.java:234)
      at getlogr_ss002.run(getlogr_ss002.java:98)
      at getlogr_ss002.main(getlogr_ss002.java:161)


      The nsk/logging/Logger/getLogger_ss/getlogr_ss002 test source:
      ===============================================================================
      // 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_ss002 {

          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_ss002";
          static java.io.PrintStream out_stream;
          static boolean verbose_mode = false; // test argument -vbs or -verbose switches to true
                                                // - for more easy failure evaluation
          static Logger test_logger;
          static Logger second_test_logger;
          
          private static void print_log_on_verbose(String message) {
              if ( verbose_mode ) {
                  out_stream.println("--> getlogr_ss002: " + message);
              }
          }
          
          private static void print_log_without_verbose(String message) {
              if ( ! verbose_mode ) {
                  out_stream.println("--> getlogr_ss002: " + message);
              }
          }
          
          public static int run(String argv[], java.io.PrintStream out) {
              int v_test_result = 0/*STATUS_PASSED*/;
              int error_check_count = 0;

              out_stream = out;

              out_stream.println("==> nsk/logging/Logger/getLogger_ss/getlogr_ss002 test LOG:");
              out_stream.println("==> test checks the getLogger(String, String) method of Logger class");
              out_stream.println(" of the java.util.logging package for case when the named Logger");
              out_stream.println(" already exists and does not yet have a localization resource bundle\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 = package_prefix + "getlogr_ss002";
              test_logger = Logger.getLogger(logger_name);

              print_log_on_verbose
                  ("check getLogger(String, String) for existing named Logger and 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(String, String) for existing named Logger and nonexisting resource
      bundle...");
                  out_stream.println
                      ("##> getlogr_ss002: FAILED: 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(String, String) for existing named Logger and nonexisting resource
      bundle...");
                      out_stream.println
                          ("##> getlogr_ss002: FAILED: Unexpected Exception (NOT MissingResourceException)
      thrown - "
                          + e.toString());
                      error_check_count++;
                  }
              }

      // logger_name = "other_logger_name";
      // test_logger = Logger.getLogger(logger_name);
              String resource_bundle_name = package_prefix + "getlogr_ss002$TestResources";
              while ( true) {
                  print_log_on_verbose
                      ("check getLogger(String, String) for existing named Logger and valid resource
      bundle...");
                  second_test_logger = Logger.getLogger(logger_name, resource_bundle_name);
                  if ( ! test_logger.equals(second_test_logger) ) {
                      print_log_without_verbose
                          ("check getLogger(String, String) for existing named Logger and valid resource
      bundle...");
                      out_stream.println("##> getlogr_ss002: FAILED: newly returned Logger is NOT the same!");
                      error_check_count++;
                      break; // there is no sense for further checks
                  }
                  else {
                      print_log_on_verbose("PASSED: newly returned Logger is the same!");
                  }

                  print_log_on_verbose("check name of returned Logger by logger.getName() method...");
                  String got_logger_name = second_test_logger.getName();
              
                  if ( !logger_name.equals(got_logger_name) ) {
                      print_log_without_verbose
                          ("check name of returned Logger by logger.getName() method...");
                      out_stream.println("##> getlogr_ss002: FAILED: getName() returned unexpected logger name
      = "
                          + got_logger_name);
                      out_stream.println("##> expected name = " + logger_name);
                      error_check_count++;
                  }
                  else {
                      print_log_on_verbose("PASSED: getName() returned expected logger name = "
                          + logger_name);
                  }

                  print_log_on_verbose
                      ("check resource bundle name for returned Logger by logger.getResourceBundleName()
      method...");
                  String got_resource_bundle_name = second_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...");
                      out_stream.println("##> getlogr_ss002: FAILED: Unexpected resource bundle name returned =
      "
                          + got_resource_bundle_name);
                      out_stream.println("##> expected name = " + resource_bundle_name);
                      error_check_count++;
                  }
                  else {
                      print_log_on_verbose("PASSED: expected resource bundle name returned = "
                          + resource_bundle_name);
                  }
                  break;
              }
              if ( error_check_count != 0 ) {
                  v_test_result = 2/*STATUS_FAILED*/;
              }
              else {
                  out_stream.println("--> getlogr_ss002: all checks for getLogger(String, String) method are
      PASSED!");
              }

              if ( v_test_result == 2/*STATUS_FAILED*/ ) {
                  out_stream.println("==> nsk/logging/Logger/getLogger_ss/getlogr_ss002 test FAILED");
              }
              else {
                  out_stream.println("==> nsk/logging/Logger/getLogger_ss/getlogr_ss002 test PASSED");
              }
              return v_test_result;
          }

          public static void main(String argv[]) {
              System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
          }

      } // end of getlogr_ss002 class
      ===============================================================================

       
      ======================================================================

            ghamiltosunw Graham Hamilton (Inactive)
            bondsunw Bond Bond (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: