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

logging APIs: Logger.addHandler(Handler) method should not add null Handler

XMLWordPrintable

    • beta
    • sparc
    • solaris_7
    • Verified



      Name: abR10010 Date: 08/24/2000




      The Java Logging APIs specification for Logger.addHandler(Handler)
      method says nothing about reaction upon a try to add null Handler.

      But the simple nsk/addhandler test shows that null Handler is added
      successfully to the logger and only much latter a NullPointerException
      is thrown when a try to log any message is done. Moreover it is
      difficult to understand what causes this NullPointerException to be
      thrown.

      It seems that there is sense to throw a NullPointerException just
      a try to add null Handler is done.


      See logs and test source:

      % java addhandler
      ==> nsk/addhandler test LOG:
      --> addhandler: addHandler() for Handler = null...
      --> addhandler: null Handler added!
      --> addhandler: logger.getHandlers()[0] = null
      --> addhandler: logger.setLevel(Level.INFO) - done!
      --> addhandler: logger.log(Level.INFO, "INFO_message") will be...
      Exception in thread "main" java.lang.NullPointerException
      at java.util.logging.Logger$PostAction.run(Logger.java:1359)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.util.logging.Logger.log(Logger.java:373)
      at java.util.logging.Logger.log(Logger.java:856)
      at addhandler.run(addhandler.java:43)
      at addhandler.main(addhandler.java:53)


      The nsk/addhandler test sourse:
      ===============================================================================
      // File: %Z%%M% %I% %E%
      // Copyright %G% Sun Microsystems, Inc. All Rights Reserved

      import java.util.logging.*;

      public class addhandler {
          static LogManager glob_log_manager;
          static Logger logger;
          
          
          public static int run(String argv[], java.io.PrintStream out) {

              System.out.println("==> nsk/addhandler test LOG:");
              
              glob_log_manager = LogManager.getLogManager();
              String logger_name = "nsk.addhandler";
              logger = Logger.getLogger(logger_name);

              System.out.println("--> addhandler: addHandler() for Handler = null...");
              Handler null_test_handler = null;
              try {
                  logger.addHandler(null_test_handler);
                  System.out.println("--> addhandler: null Handler added!");
              }
              catch (Exception e) {
                  System.out.println("--> addhandler: Exception thrown: " + e.toString());
                  return 0;
              }

              System.out.println
                  ("--> addhandler: logger.getHandlers()[0] = " + logger.getHandlers()[0]);

              logger.setLevel(Level.INFO);
              System.out.println
                  ("--> addhandler: logger.setLevel(Level.INFO) - done!");

              System.out.println
                  ("--> addhandler: logger.log(Level.INFO, \"INFO_message\") will be...");
              logger.log(Level.INFO, "INFO_message");

              glob_log_manager.flush();

              System.out.println("");
              System.out.println("==> nsk/addhandler finished!");
              return 0;
          }

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

      } // end of addhandler class
      ===============================================================================

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

      Name: elR10090 Date: 02/01/2001


      This bug affects the following testbase_nsk test:
          nsk/logging/Logger/addHandler/addhandler001


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

            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: