Logger.log should call getHandlers

Martin Buchholz martinrb at google.com
Tue Apr 14 21:37:56 UTC 2009


I've updated my PATCH with more self-flagellation penance tests,
but which also have an ulterior motive, as will be revealed in a followon msg.

PATCH to my patch
http://cr.openjdk.java.net/~martin/getHandlers
follows:

diff --git a/test/java/util/logging/LoggerSubclass.java
b/test/java/util/logging/LoggerSubclass.java
--- a/test/java/util/logging/LoggerSubclass.java
+++ b/test/java/util/logging/LoggerSubclass.java
@@ -32,12 +32,15 @@
 import java.util.logging.Logger;
 import java.util.logging.LogRecord;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;

 public class LoggerSubclass {
     void test(String[] args) {
         final String name = "myLogger";
         final String message = "myMessage";
         final AtomicInteger getHandlerCount = new AtomicInteger(0);
+        final AtomicLong lastSequenceNumber = new AtomicLong(-1L);
+        final AtomicInteger lastThreadID = new AtomicInteger(-1);
         final Logger logger = new Logger(name, null) {
             public Handler[] getHandlers() {
                 getHandlerCount.getAndIncrement();
@@ -59,6 +62,15 @@
                 equal(l.getSourceMethodName(), "test");
                 equal(l.getThrown(), null);
                 equal(l.getLevel(), Level.WARNING);
+
+                if (lastSequenceNumber.get() != -1) {
+                    equal(lastSequenceNumber.get() + 1,
+                          l.getSequenceNumber());
+                    equal(lastThreadID.get(),
+                          l.getThreadID());
+                }
+                lastSequenceNumber.set(l.getSequenceNumber());
+                lastThreadID.set(l.getThreadID());
             }});
         for (int i = 1; i < 4; i++) {
             logger.warning(message); // Should invoke getHandlers()


Martin

On Mon, Apr 13, 2009 at 19:15, Martin Buchholz <martinrb at google.com> wrote:
> Hi Swamy
>
> Our recent change
>
> changeset:   810:6eac3829cb41
> user:        martin
> date:        Tue Jan 27 15:04:30 2009 -0800
> summary:     6797480: Remove synchronization bottleneck in logger
>
> unfortunately introduced a serious bug.
>
> Logger.log should call Logger.getHandlers(), not Logger.handlers,
> because getHandlers may be overriden in a subclass.
> Notably, the root logger is such a subclass with a
> non-trivial getHandlers method.
>
> Here's the obvious fix, with a regression test that
> includes "penance" for our having broken j.u.l.
> by adding some much-needed  tests for never-before-exercised code.
>
> Please review and file a bug.
>
> PATCH is here:
> http://cr.openjdk.java.net/~martin/getHandlers
>
> Martin
>



More information about the core-libs-dev mailing list