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

impossible to specify directories to logging FileHandler unless they exist

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.4.2
    • Fix Version/s: 8
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b66
    • CPU:
      x86
    • OS:
      windows_2000
    • Verification:
      Verified

      Description

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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195] SP4


      A DESCRIPTION OF THE PROBLEM :
      if you specify a patern to the FileHandler that contains directories that don't currently exist then the FileHandler will fail to initialise even if the directories can be created

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      configure a FileHandler for logging that uses a directory that can be created but doesn't exist.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      the directories are created if the user has the permissions to do so
      ACTUAL -
      exception is thrown, FIleHandler is not configured.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      C:\>java -Djava.util.logging.config.file=c:\logging.properties LogTest
      Can't load log handler "java.util.logging.FileHandler"
      java.io.IOException: Couldn't get lock for %h/.myco/myapp/log%u.%g.log
      java.io.IOException: Couldn't get lock for %h/.myco/myapp/log%u.%g.log
              at java.util.logging.FileHandler.openFiles(FileHandler.java:361)
              at java.util.logging.FileHandler.<init>(FileHandler.java:207)
              at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
              at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
              at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
              at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
              at java.lang.Class.newInstance0(Class.java:308)
              at java.lang.Class.newInstance(Class.java:261)
              at java.util.logging.LogManager$5.run(LogManager.java:784)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.util.logging.LogManager.initializeGlobalHandlers(LogManager.java:776)
              at java.util.logging.LogManager.access$900(LogManager.java:114)
              at java.util.logging.LogManager$RootLogger.getHandlers(LogManager.java:883)
              at java.util.logging.Logger.log(Logger.java:420)
              at java.util.logging.Logger.doLog(Logger.java:446)
              at java.util.logging.Logger.log(Logger.java:469)
              at LogTest.main(LogTest.java:7)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      -- logging.properties --
      handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
      .level= ALL
      java.util.logging.FileHandler.pattern = %h/.myco/myapp/log%u.%g.log
      -- end logging.properties --

      -- LogTest.java --

      import java.util.logging.*;

      public class LogTest {

      public static void main(String[] args) {
      Logger log = Logger.getLogger(LogTest.class.getName());
      log.log(Level.SEVERE, "Hello World");
      }

      }

      -- end LogTest.java --


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

      CUSTOMER SUBMITTED WORKAROUND :
      have to make directories first, but then have to parse the pattern.
      the generate method in FileHandler is not exposed so need to re-invent the wheel.

      Otherwise is a possible one line fix in FileHandler.java:openFiles(),
      line 369
      synchronized(locks) {
      if (locks.get(lockFileName) != null) {
      // We already own this lock, for a different FileHandler
      // object. Try again.
      continue;
      }
      FileChannel fc;
      try {
      + lockFileName.getParent().mkdirs();
      lockStream = new FileOutputStream(lockFileName);
      fc = lockStream.getChannel();
      } catch (IOException ix) {
      // We got an IOException while trying to open the file.
      // Try the next file.
      continue;
      }
      ###@###.### 2005-03-22 04:40:08 GMT

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jgish Jim Gish
              Reporter:
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: