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

Unable to create Logger during JVM shutdown

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      06
    • CPU:
      x86
    • OS:
      linux
    • Verification:
      Verified

      Backports

        Description

        Name: dk106046 Date: 02/02/2004

        Synopsis:
        The Logger object used in FileSystemPreferences.java is not created until a message must be passed to it. In this testcase, this occurs when the JVM is shutting down. Part of the creating of a Logger is to register a shutdown hook, which cant be done as we are already shutting down.

        OS:
        Linux - all architectures, all flavours

        Full JDK Version:
        java version "1.4.2_03"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
        Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

        Problem:
        The latest version of FileSystemPreferences.java has replaced the declaration:

             private static final Logger logger = Logger.getLogger("java.util.prefs");

        with the function:

            private static Logger getLogger() {
                return Logger.getLogger("java.util.prefs");
            }

        and all calls to the logger now use the static function getLogger().info (for example) rather than the local variable logger.info.

        This means that the Logger object is not created until it is first used to print warnings. In the case detailed below, where the dir /etc/.java/.systemPref exists but is not writable, the Logger is not used until the JVM is shutting down. The Logger is therefore created at this point, which in turn creates a LogManager, which in turn attempts to create a Shutdown hook, which cant be done, as we are already shutting down, hence the "Shutdown in Progress" error.

        This problem occurs in JDK 1.4.2_03 but not occur in 1.4.1_07.

        Reproduction of Error:
        Create the file /etc/.java/.systemPrefs as root.
        Ensure that both the .java and the .systemPrefs directories are owned by root, and have permission 755, preventing normal users writing to them.

        Run the following Java testcase, as a non-root standard user:

        ___________________
        import java.lang.*;
        import java.util.prefs.*;
        import java.io.*;

        public class vPref {

            public static void main(String argv[]) {
                vPref test = new vPref();
                test.SimplePreferencetest006();
                System.exit(0);
            }

            public void SimplePreferencetest006() {
                Preferences prefs = Preferences.systemNodeForPackage(getClass());
                Preferences prefs1 = prefs.node("/com/acme/widget");
                boolean passed = true;
                try {
                    prefs1.removeNode();
                } catch (Exception e) {
                }
                return;
            }
        }
        __________________________

        Error Message:
        java.lang.ExceptionInInitializerError
                at java.util.logging.Logger.getLogger(Logger.java:227)
                at java.util.logging.Logger.<clinit>(Logger.java:181)
                at java.util.prefs.FileSystemPreferences.getLogger(FileSystemPreferences.java:52)
                at java.util.prefs.FileSystemPreferences.checkLockFile0ErrorCode(FileSystemPreferences.java:923)
                at java.util.prefs.FileSystemPreferences.lockFile(FileSystemPreferences.java:908)
                at java.util.prefs.FileSystemPreferences.sync(FileSystemPreferences.java:714)
                at java.util.prefs.FileSystemPreferences.flush(FileSystemPreferences.java:807)
                at java.util.prefs.FileSystemPreferences.syncWorld(FileSystemPreferences.java:458)
                at java.util.prefs.FileSystemPreferences.access$1200(FileSystemPreferences.java:33)
                at java.util.prefs.FileSystemPreferences$6.run(FileSystemPreferences.java:429)
        Caused by: java.lang.IllegalStateException: Shutdown in progress
                at java.lang.Shutdown.add(Shutdown.java:110)
                at java.lang.Runtime.addShutdownHook(Runtime.java:222)
                at java.util.logging.LogManager.<init>(LogManager.java:197)
                at java.util.logging.LogManager$1.run(LogManager.java:155)
                at java.security.AccessController.doPrivileged1(Native Method)
                at java.security.AccessController.doPrivileged(AccessController.java:286)
                at java.util.logging.LogManager.<clinit>(LogManager.java:141)
                ... 10 more

        Fix:
        Replacing the function getLogger() in FileSystemPreferences.java with a static final Logger object, and replacing the calls to getLogger with the local object logger, as was done in 1.4.1 will stop this problem occuring, by ensuring that the Logger object is created when the FileSystemPreferences class is used, regardless of whether the Logger itself is used.

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

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                caustinsunw Calvin Austin (Inactive)
                Reporter:
                dkorbel David Korbel (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: