United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-8007611 logging behavior in applet changed
JDK-8007611 : logging behavior in applet changed

Details
Type:
Bug
Submit Date:
2013-02-06
Status:
Closed
Updated Date:
2013-07-31
Project Name:
JDK
Resolved Date:
2013-02-07
Component:
core-libs
OS:
Sub-Component:
java.util.logging
CPU:
Priority:
P2
Resolution:
Fixed
Affected Versions:
7u13
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:

Sub Tasks

Description
the following code works 7u11 as applet:

import java.applet.Applet;
import java.util.logging.*;

public class Hello extends Applet {

      private static final Logger log = Logger.getLogger("Hello");

   @Override
   public void init() {
      log.info("Hello!!");
      System.out.println("mmmhhhh....");
   }
   // TODO overwrite start(), stop() and destroy() methods
}


Java console would show output:

05-feb-2013 11:18:50 Hello init
INFO: Hello!!


With 7u13 - it does not output in java console
                                    

Comments
when it works, I see the following:

In Java Console:

Feb 05, 2013 7:35:47 PM HelloWorld init
INFO: Hello!!

In log output file:

<record>
  <date>2013-02-05T19:35:47</date>
  <millis>1360121747246</millis>
  <sequence>3</sequence>
  <logger>sun.plugin</logger>
  <level>FINE</level>
  <class>com.sun.deploy.trace.LoggerTraceListener</class>
  <method>print</method>
  <thread>8</thread>
  <message>Feb 05, 2013 7:35:47 PM HelloWorld init

INFO: Hello!!

</message>
</record>
                                     
2013-02-06
Logging initialization is fragile and complex.  The worst is that it ignores all exception silently.  I can agree that error in logging should not impact the application runtime but ignoring error during logging initialization makes bugs to creep in and hard to diagnose.

LogManager.readPrimordialConfiguration fails with NPE as it's called during LogManager.<clinit>.

Can't read logging configuration:
java.lang.NullPointerException
        at java.util.logging.LogManager$LoggerContext.addLocalLogger(LogManager.java:502)
        at java.util.logging.LogManager.getUserContext(LogManager.java:366)
        at java.util.logging.LogManager.contexts(LogManager.java:380)
        at java.util.logging.LogManager.reset(LogManager.java:1014)
        at java.util.logging.LogManager.readConfiguration(LogManager.java:1094)
        at java.util.logging.LogManager.readConfiguration(LogManager.java:987)
        at java.util.logging.LogManager$2.run(LogManager.java:288)
        at java.util.logging.LogManager$2.run(LogManager.java:286)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.util.logging.LogManager.readPrimordialConfiguration(LogManager.java:286)
        at java.util.logging.LogManager.getLogManager(LogManager.java:268)
        at java.util.logging.Logger.<init>(Logger.java:252)
        at java.util.logging.LogManager$RootLogger.<init>(LogManager.java:1320)
        at java.util.logging.LogManager$RootLogger.<init>(LogManager.java:1318)
        at java.util.logging.LogManager$1.run(LogManager.java:199)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.util.logging.LogManager.<clinit>(LogManager.java:176)
        at java.util.logging.Logger.demandLogger(Logger.java:307)
        at java.util.logging.Logger.getLogger(Logger.java:370)
        at Hello.<clinit>(Hello.java:6)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:
57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorIm
pl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
        at java.lang.Class.newInstance0(Class.java:374)
        at java.lang.Class.newInstance(Class.java:327)
        at sun.applet.AppletPanel.createApplet(AppletPanel.java:793)
        at sun.applet.AppletPanel.runLoader(AppletPanel.java:722)
        at sun.applet.AppletPanel.run(AppletPanel.java:379)
        at java.lang.Thread.run(Thread.java:722)
                                     
2013-02-06
testcase:  http://javaweb.us.oracle.com/~tvng/8007611/HelloWorld.html

you can see applet source in the directory.

tested on win7 32-bit.
                                     
2013-02-06
original report:  http://stackoverflow.com/questions/14705326/java-applet-logging-7u13
                                     
2013-02-06
I can reproduce the problem with 7u13.   I checked the deployment fixes in 7u13 - don't see anything that is related to loggin.

I then tried to replace the rt.jar in 7u13 with copy from 7u11 - it works.

Is there some fix related to logging API in 7u13 that might caused this ?
                                     
2013-02-06
Suggested fix on LogManager:
diff --git a/src/share/classes/java/util/logging/LogManager.java b/src/share/classes/java/util/logging/LogManager.java
--- a/src/share/classes/java/util/logging/LogManager.java
+++ b/src/share/classes/java/util/logging/LogManager.java
@@ -363,6 +363,7 @@
                         context = userContext;
                     } else {
                         context = new LoggerContext();
+                        if (manager.rootLogger != null)
                         context.addLocalLogger(manager.rootLogger);
                     }
                     javaAwtAccess.put(ecx, LoggerContext.class, context);


this NPE will be thrown only when creating the rootLogger during initialization.  After that rootLogger can be added to the user context.  Also the global handlers for the rootLogger is reinitialized the first time it is accessed (due to the LogManager and Logger initialization dependency)

For jdk8, I'll add a system property for testing purpose if set it will throw the exception during initialization instead of silently ignore it.
                                     
2013-02-06
Workaround: set -Djava.util.logging.config.file=<jre>/lib/logging.properties via Java control panel.

This will workaround the logging initialization issue.  Thomas has kindly helped verify that this workaround works with 7u13.
                                     
2013-02-06
URL:   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/1143bb5e7064
User:  lana
Date:  2013-03-15 17:04:08 +0000

                                     
2013-03-15
A regression due to the fix for JDK-6664509 in 7u13.  This affects all updated releases.

SA review:
  http://sa.sfbay.sun.com/mail-archive/8007611-cpu-review/

Reviewed-by: alanb, jgish

A regression has been modified to reproduce this failure and verify the fix.
   http://bluebird.us.oracle.com/export/mchung/ws/7u13/7u13-logging/jdk/8007611/ 
                                     
2013-02-07



Hardware and Software, Engineered to Work Together