JDK-4515935 : LogRecord lazy class/method name inference can be incorrect/unreliable
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.logging
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Future Project
  • OS: generic
  • CPU: generic
  • Submitted: 2001-10-17
  • Updated: 2024-04-12
  • Resolved: 2005-05-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Relates :  
Description
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)



Comments
EVALUATION Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=21354
10-09-2007

WORK AROUND Always use Logger.logp(...)
06-07-2004