JDK-8017174 : NPE when using Logger.getAnonymousLogger or LogManager.getLogManager().getLogger
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.logging
  • Affected Version: 7u25,8
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: os_x
  • Submitted: 2013-06-20
  • Updated: 2014-08-05
  • Resolved: 2013-07-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.
JDK 6 JDK 7 JDK 8
6u81Fixed 7u40Fixed 8 b98Fixed
Related Reports
Duplicate :  
Duplicate :  
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
15-07-2013

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.
04-07-2013

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.
20-06-2013

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
20-06-2013

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.
20-06-2013