United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-8017174 NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
JDK-8017174 : NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger

Details
Type:
Bug
Submit Date:
2013-06-20
Status:
Closed
Updated Date:
2014-02-12
Project Name:
JDK
Resolved Date:
2013-07-02
Component:
core-libs
OS:
os_x
Sub-Component:
java.util.logging
CPU:
Priority:
P2
Resolution:
Fixed
Affected Versions:
7u25,8
Fixed Versions:

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

Sub Tasks

Description
FULL PRODUCT VERSION :
java version  " 1.7.0_25 " 
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Occurs on multiple Platforms reproduced on OS X and Windows

A DESCRIPTION OF THE PROBLEM :
When using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger in an applet a NPE occurs on the second load of the applet in the browser session.

If the browser is restarted the applet loads fine until the next reload.

REGRESSION: I could only choose 7 update 25 or 7 update 40 in the regression drop down. The issue only occurs since 7 update 25 but not in 7 update 21

REGRESSION.  Last worked in version 7u25

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create an applet from the code below.
2. Load it in a browser
3. Reload the page with the applet

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No NPE on reload
ACTUAL -
NPE on reload

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
at java.util.logging.Logger.doSetParent(Logger.java:1593)
at java.util.logging.Logger.getAnonymousLogger(Logger.java:534)
at java.util.logging.Logger.getAnonymousLogger(Logger.java:495)
at TestApplet.init(TestApplet.java:12)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Thread.java:724)

AND

java.lang.NullPointerException
at java.util.logging.Logger.setParent(Logger.java:1558)
at TestApplet$EditorLogger.<init>(TestApplet.java:30)
at TestApplet.init(TestApplet.java:18)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Thread.java:724)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.logging.LogManager;
import java.util.logging.Logger;

import javax.swing.JApplet;

public class TestApplet extends JApplet {
    
    private EditorLogger editorLogger;
    public void init() {
        
        try {
            Logger logger = Logger.getAnonymousLogger();
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        try {
            this.editorLogger = new EditorLogger();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public class EditorLogger extends Logger {
        
        public EditorLogger() {
            super(null, null);
            System.out.println( " LogManager:  " +LogManager.getLogManager());
            System.out.println( " getLogger:  " +LogManager.getLogManager().getLogger( "  " ));
            setParent(LogManager.getLogManager().getLogger( "  " ));
        }
    }
}

---------- END SOURCE ----------
                                    

Comments
Backport to 7u40 had request label and had been approved. Not sure it is still needed, but I also approved mster bug for 7u40
                                     
2013-07-15
In the code sample above:

            setParent(LogManager.getLogManager().getLogger( " " ));

should always generate a NPE - because there is a spurious white space between the double quotes. The name of the root logger is "" not " ".
But that may just be a typo when the code was pasted.



                                     
2013-06-20
When JDK-8004584 was being fixed, an initialization issue related to user context and root logger was uncovered in LogManager and hence the ensureRootLogger method was added and called by the LoggerContext.addLocalLogger method [1].  LoggerContext.findLogger (we also need to determine which other methods depending the existence of root logger) has to call ensureRootLogger so that a newly created user context will have the root logger.  

[1] http://hg.openjdk.java.net/jdk7u/jdk7u-dev/jdk/rev/846304f476f1

                                     
2013-06-20
I managed to reproduce the issue.

In 7u25 using the applet viewer - I get the stack traces as above when reloading the applet.
In 7u25 using a file browser - I get the exception right away at applet initialization - and also on reload.

 
                                     
2013-06-20
URL:   http://hg.openjdk.java.net/jdk8/tl/jdk/rev/020f023f87d1
User:  dfuchs
Date:  2013-07-02 10:07:49 +0000

                                     
2013-07-02
There may be an ugly workaround for that issue:

If the applet calls:

   Logger.getLogger("foo"); 

before accessing any other logger it should trigger the addition of the root logger in the applet's logging context.
After that calls to LogManager.getLogManager().getLogger("") should no longer return null.
Seems to be working on a dummy applet with 7u25. 
                                     
2013-07-04
URL:   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/020f023f87d1
User:  lana
Date:  2013-07-05 18:35:47 +0000

                                     
2013-07-05



Hardware and Software, Engineered to Work Together