United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6427854 : (se) NullPointerException in Selector.open()

Details
Type:
Bug
Submit Date:
2006-05-19
Status:
Closed
Updated Date:
2011-05-18
Project Name:
JDK
Resolved Date:
2011-05-18
Component:
core-libs
OS:
windows_xp
Sub-Component:
java.nio
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:

Related Reports
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
bug is OS independent

A DESCRIPTION OF THE PROBLEM :
sun.nio.ch.Util contains code which is not thread safe and can throw a NullPointerException:

    private static String bugLevel = null;

    static boolean atBugLevel(String bl) {		// package-private
        if (bugLevel == null) {
            if (!sun.misc.VM.isBooted())
                return false;
            java.security.PrivilegedAction pa =
                new GetPropertyAction("sun.nio.ch.bugLevel");
// the next line can reset bugLevel to null
            bugLevel = (String)AccessController.doPrivileged(pa);
            if (bugLevel == null)
                bugLevel = "";
        }
        return (bugLevel != null) && bugLevel.equals(bl);
    }

Suppose that two threads enter the "if (buglevel == null)" body at the same time. The first one runs until the return line and gets scheduled out right after the (buglevel != null) check. The second one then runs until right after the doPrivileged() call, sets bugLevel to null and gets scheduled out. The first one continues and hits a NullPointerException while calling bugLevel.equals() with bugLevel being null.

The chances to hit this are low, but I did see it in a test run (see stacktrace below).


ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
   at sun.nio.ch.Util.atBugLevel(Util.java:290)
   at sun.nio.ch.SelectorImpl.<init>(SelectorImpl.java:40)
   at sun.nio.ch.WindowsSelectorImpl.<init>(WindowsSelectorImpl.java:104)
   at sun.nio.ch.WindowsSelectorProvider.openSelector(WindowsSelectorProvider.java:26)
   at java.nio.channels.Selector.open(Selector.java:209)


REPRODUCIBILITY :
This bug can be reproduced rarely.

                                    

Comments
EVALUATION

Yes, there is a timing issue. We expect the issue is rare and will fix early in dolphin.
                                     
2006-06-12



Hardware and Software, Engineered to Work Together