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

LogRecord lazy class/method name inference can be incorrect/unreliable

XMLWordPrintable

      java.util.logging.LogRecord's current lazy caller inference scheme is
      unreliable in two ways.

      First, LogRecord.inferCaller() assumes that the original caller of the log()
      method will still be on the stack when the source class/method name is queried
      (and lazily inferred). This will not be the case if the responsible Handler
      queues the LogRecord for later processing (e.g., as is done by
      java.util.logging.MemoryHandler), and can result in log messages with incorrect
      source class/method information (as is demonstrated below).

      Second, if the LogRecord is serialized instead of printed, there's no trigger
      in LogRecord.writeObject() to lazily fill in values for source class/method
      names, even though such information may still be available.

      The attached sample code demonstrates these problems. The attachment contains
      the following files:

          Foo.java program which logs messages from
                                      two different methods

          SerialHandler.java log handler which serializes LogRecords
                                      before printing them

          logging.console logging config file for straight console output

          logging.memory logging config file using MemoryHandler

          logging.serial logging config file using SerialHandler

      Output from running with straight console logging. Source class and method
      names, as expected, are accurate.

        $ java -Djava.util.logging.config.file=logging.console Foo
        Oct 17, 2001 4:48:30 PM Foo first
        FINE: foo
        Oct 17, 2001 4:48:30 PM Bar second
        INFO: bar

      Output from running with MemoryHandler installed. Source class and method
      name for the first log message is incorrectly set to that of the second (which
      triggered the MemoryHandler push).

        $ java -Djava.util.logging.config.file=logging.memory Foo
        Oct 17, 2001 4:48:39 PM Bar second
        FINE: foo
        Oct 17, 2001 4:48:39 PM Bar second
        INFO: bar

      Output from running with SerialHandler installed. All source class and method
      name information is lost.

        $ java -Djava.util.logging.config.file=logging.serial Foo
        Oct 17, 2001 4:48:46 PM FooLog
        FINE: foo
        Oct 17, 2001 4:48:47 PM FooLog
        INFO: bar

      The version of java used in above tests:

        $ java -version
        java version "1.4.0-beta3"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b83)
        Java HotSpot(TM) Client VM (build 1.4.0-beta3-b83, mixed mode)


            Unassigned Unassigned
            mwarressunw Michael Warres (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: