FileHandler/Logger doesn't delete lockfile - backport the fix for 4775533 to 1.4.2

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Future Project
    • Priority: P4
    • None
    • Affects Version/s: 1.4.2
    • Component/s: core-libs

      FULL PRODUCT VERSION :
      java version "1.4.2_07"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_07-b05)
      Java HotSpot(TM) Client VM (build 1.4.2_07-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      This is copy and pasted from Bug ID 4775533.
      Although it would be nice to migrate to J2SE 5.0, that is not an option at this time.

      A DESCRIPTION OF THE PROBLEM :
      Once this Java program is finished running, there is a
      lockfile called "LogDemo.txt.lck" lying around, that wasn't
      there before, created (but not deleted) by the FileHandler
      object.



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      // Filename: LogDemo.java

      import java.io.*;
      import java.util.logging.*;

      public final class LogDemo
      {
          public static void main(String[] args)
          {
              Logger logger = null; // A logger
              FileHandler fh = null; // The logger output will go here

              try
              {
                  logger = Logger.getLogger("LogDemo");
                  logger.setUseParentHandlers(false); // Disable console output

                  fh = new FileHandler("LogDemo.txt");
                  logger.addHandler(fh);

                  logger.setLevel(Level.ALL);
                  logger.info("Hey hey hey!");
                  throwSomething();
              }
              catch (Throwable e)
              {
                  String errmsg = "AN EXCEPTION WAS THROWN:\n" + getStackTrace(e);
                  //System.err.println(errmsg);
                  if (logger != null)
                      logger.severe(errmsg);
                  return;
              }
              finally
              {
                  /*
                  ** Does any of the code in this block need to be here?
                  */
                  if (fh != null)
                      fh.close();
                  logger.removeHandler(fh);
              }
          }

          /*
          ** Return a stack trace of the given exception, in a String:
          */
          private static final String getStackTrace(Throwable e)
          {
              StringWriter s = new StringWriter();
              e.printStackTrace(new PrintWriter(s));
              return s.toString();
          }

          /*
          ** Throw an exception on purpose:
          */
          private static void throwSomething() throws AssertionError
          {
              throw new AssertionError("Ha, ha! You're history, dude!");
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Delete the lock file manually, or just learn to live with
      it.
      (Review ID: 158666)
      ======================================================================

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. java LogDemo

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The FileHandler instance should clean up after itself. In
       xxxxx words, it should make sure that the "LogDemo.txt.lck"
      file gets deleted, upon exit.
      ACTUAL -
      The .lck files are not deleted. (And .1, .2 files remain, as well, when concurrent access happens.)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      // Filename: LogDemo.java

      import java.io.*;
      import java.util.logging.*;

      public final class LogDemo
      {
          public static void main(String[] args)
          {
              Logger logger = null; // A logger
              FileHandler fh = null; // The logger output will go here

              try
              {
                  logger = Logger.getLogger("LogDemo");
                  logger.setUseParentHandlers(false); // Disable console output

                  fh = new FileHandler("LogDemo.txt");
                  logger.addHandler(fh);

                  logger.setLevel(Level.ALL);
                  logger.info("Hey hey hey!");
                  throwSomething();
              }
              catch (Throwable e)
              {
                  String errmsg = "AN EXCEPTION WAS THROWN:\n" + getStackTrace(e);
                  //System.err.println(errmsg);
                  if (logger != null)
                      logger.severe(errmsg);
                  return;
              }
              finally
              {
                  /*
                  ** Does any of the code in this block need to be here?
                  */
                  if (fh != null)
                      fh.close();
                  logger.removeHandler(fh);
              }
          }

          /*
          ** Return a stack trace of the given exception, in a String:
          */
          private static final String getStackTrace(Throwable e)
          {
              StringWriter s = new StringWriter();
              e.printStackTrace(new PrintWriter(s));
              return s.toString();
          }

          /*
          ** Throw an exception on purpose:
          */
          private static void throwSomething() throws AssertionError
          {
              throw new AssertionError("Ha, ha! You're history, dude!");
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Delete the lock file manually, or just learn to live with
      it.

      In my particular situation, we need one file, and we're getting 2n files, where n is the number of concurrent sessions that have ever happened, on both sides of our hallway...
      ###@###.### 2005-05-25 08:29:48 GMT

            Assignee:
            Unassigned
            Reporter:
            Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: